如何查找整数和文本值(过滤器&搜索)

发布于 2025-02-01 05:19:01 字数 2257 浏览 6 评论 0原文

我通过Power Apps中的应用程序将数据源连接到SQL Server中的数据库,我利用画廊显示数据,并且我有文本条目在该图库中搜索特定数据。

我想执行搜索文本类型数据和数字类型数据的搜索,我在表中使用的数据类型以及我在表中使用的列:

NoEmployee int,
NameEmployee varchar,
Job varchar,
Department varchar,

我正在使用图库中的项目属性来执行两个数字的搜索和文本类型数据我使用以下语法。

Search(Filter(DataSourceEmployee;NoEmployee = Value(txtSearchText.Text));;DataSourceEmployee;txtSearchText.Text;"NameEmployee";"Department";"Job")

上述语法给我以下错误:

'搜索'函数的参数无效

文档我一直在阅读搜索功能不允许我搜索整数值。

然后,结合两个函数的想法在我身上发生,我不知道这是正确的事情。

正如我提到的,我需要搜索我提到的4列,如果使用以下搜索功能,它将在文本类型列中搜索我而毫无问题。

Search(DataSourceEmployee;txtSearchText.Text;"NameEmployee";"Department";"Job")

如果我使用过滤器函数,它将为整数类型列而没有任何问题搜索我。

Filter(DataSourceEmployee;NoEmployee = Value(txtSearchText.Text))

我想知道是否有一种方法可以结合这两个函数,以通过四列执行搜索,或者我可以使用哪些其他功能来搜索数字值,而不会丢失对文本值的搜索。

更新1:

基于提供的最后一个可能的答案,我添加了我使用的语法,但是如果没有获得令人满意的结果,它仅执行与noemployee ,而不是文本类型列。

IfError( Filter(DataSourceEmployee,NoEmployee=Value(txtSearchText.Text)), Filter(DataSourceEmployee,StartsWith(NameEmployee,txtSearchText.Text)))

更新2:

基于他们给我的最后一个答案,我在项目 Gallery Control的属性中执行了以下功能,我尝试执行搜索类型int的列以及varchar的列,而我没有得到结果。

我使用的函数如下:

SortByColumns(
    Filter(
        colEmployees,
        If(
            !IsBlank(txtSearchText.Text),
            Or(
                txtSearchText.Text in NoEmployee,
                txtSearchText.Text in NameEmpleado,
                txtSearchText.Text in Job,
                txtSearchText.Text in Department
            ),
            1 = 1
        )
    ),
    "NoEmployee",
    Ascending
)

附加答案表示我在应用程序控制的onstart属性中添加的答案。

ClearCollect(colEmployees,DataSourceEmployee)

I have my data source connected to database in SQL Server through an application in Power Apps, I am making use of Gallery to display the data and I have a text entry to search for specific data in that gallery.

I would like to perform the search for text type data and numeric type data, I leave below the data type and the columns that I use in my table:

NoEmployee int,
NameEmployee varchar,
Job varchar,
Department varchar,

I am making use of the Items property in the Gallery to perform the search for both numeric and text type data where I use the following syntax.

Search(Filter(DataSourceEmployee;NoEmployee = Value(txtSearchText.Text));;DataSourceEmployee;txtSearchText.Text;"NameEmployee";"Department";"Job")

The above syntax gives me the following error:

'Search' function has invalid arguments

Among the documentation that I have been reading the Search function does not allow me to search for integer values.

Then the idea of ​​combining the two functions occurs to me, I don't know if it's the right thing to do.

As I mentioned, I need to search for the 4 columns that I mentioned, if I use the following Search function, it searches me without problem for the text type columns.

Search(DataSourceEmployee;txtSearchText.Text;"NameEmployee";"Department";"Job")

If I use the Filter function, it searches me without any problem for the integer type column.

Filter(DataSourceEmployee;NoEmployee = Value(txtSearchText.Text))

I would like to know if there is a way to combine these two functions in order to perform the search through the four columns or what other function I can use to search for number values ​​without losing the search for text values.

Update 1:

Based on the last possible answer provided, I add the syntax that I have used, but without obtaining a satisfactory result, it only performs a search for the numeric data type column which corresponds to NoEmployee and not for the text type column.

IfError( Filter(DataSourceEmployee,NoEmployee=Value(txtSearchText.Text)), Filter(DataSourceEmployee,StartsWith(NameEmployee,txtSearchText.Text)))

Update 2:

Based on the last answer they give me I have performed the following function in the Items property of Gallery Control, I try to perform the search for the column of type INT as well as those of VARCHAR and in none I get results.

The function I have used is as follows:

SortByColumns(
    Filter(
        colEmployees,
        If(
            !IsBlank(txtSearchText.Text),
            Or(
                txtSearchText.Text in NoEmployee,
                txtSearchText.Text in NameEmpleado,
                txtSearchText.Text in Job,
                txtSearchText.Text in Department
            ),
            1 = 1
        )
    ),
    "NoEmployee",
    Ascending
)

Additional as the answer indicates I have added in the OnStart property of the application control the following:

ClearCollect(colEmployees,DataSourceEmployee)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剑心龙吟 2025-02-08 05:19:01

sortbycolumn功能中,而不是search中使用过滤器。无论类型如何,您都可以轻松地搜索所有想要的列。在这里,我展示了如何通过所有4列搜索empnumberint -Type列,其余为nvarchar

您可以按任何列排序上升降序

插图:

”在此处输入图像说明“

代码:

  • 将其放在应用程序控制的onstart上:

    • clearCollect(colemployees,雇员_dev)
    • 其中lightee_dev是下面显示的SQL表
  • 项目画廊控制的属性:

SortByColumns(
    Filter(colEmployees, 
        If(
            !IsBlank(txtSearch.Text),
            Or(
                txtSearch.Text in EmpNumber,
                txtSearch.Text in EmpName,
                txtSearch.Text in Job,
                txtSearch.Text in Deparment
            ),
            1=1
        )
    ),
    "EmpNumber",
    Ascending
)
  • 放置4个标签控件以显示数据
    • 将其文本属性设置为thisItem。< columnName>

数据: sql数据库已连接到PowerApp Canvas App

-- Create a new table called 'EMPLOYEE_DEV' in schema 'dbo'
-- Drop the table if it already exists
IF OBJECT_ID('dbo.EMPLOYEE_DEV', 'U') IS NOT NULL
DROP TABLE dbo.EMPLOYEE_DEV
GO
-- Create the table in the specified schema
CREATE TABLE dbo.EMPLOYEE_DEV
(
    EmpTblID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
    EmpNumber INT,
    EmpName VARCHAR(255),
    Job VARCHAR(255),
    Deparment VARCHAR(255)
);

INSERT INTO dbo.EMPLOYEE_DEV (EmpNumber, EmpName, Job, Deparment)

VALUES 
(123, 'John', 'Developer', 'IT'),
(234, 'Jane', 'Developer', 'IT'),
(345, 'Jim', 'Project Manager', 'ENG'),
(456, 'Joey', 'Manager', 'ENG')

Use a Filter within a SortByColumn function rather than Search. You can easily search by all columns you want regardless of type. Here I show how to search by all 4 columns where EmpNumber is an INT-type column and the rest are NVARCHAR.

You can sort by any column, Ascending or Descending.

Illustration:

enter image description here

Code:

  • Place this on OnStart of the App control:

    • ClearCollect(colEmployees, EMPLOYEE_DEV)
    • Where EMPLOYEE_DEV is the SQL table shown below
  • Place this on the Items property of the Gallery control:

SortByColumns(
    Filter(colEmployees, 
        If(
            !IsBlank(txtSearch.Text),
            Or(
                txtSearch.Text in EmpNumber,
                txtSearch.Text in EmpName,
                txtSearch.Text in Job,
                txtSearch.Text in Deparment
            ),
            1=1
        )
    ),
    "EmpNumber",
    Ascending
)
  • Place 4 Label controls to display the data
    • Set their Text properties to ThisItem.<ColumnName>

Data: SQL Database connected to PowerApp Canvas app

-- Create a new table called 'EMPLOYEE_DEV' in schema 'dbo'
-- Drop the table if it already exists
IF OBJECT_ID('dbo.EMPLOYEE_DEV', 'U') IS NOT NULL
DROP TABLE dbo.EMPLOYEE_DEV
GO
-- Create the table in the specified schema
CREATE TABLE dbo.EMPLOYEE_DEV
(
    EmpTblID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
    EmpNumber INT,
    EmpName VARCHAR(255),
    Job VARCHAR(255),
    Deparment VARCHAR(255)
);

INSERT INTO dbo.EMPLOYEE_DEV (EmpNumber, EmpName, Job, Deparment)

VALUES 
(123, 'John', 'Developer', 'IT'),
(234, 'Jane', 'Developer', 'IT'),
(345, 'Jim', 'Project Manager', 'ENG'),
(456, 'Joey', 'Manager', 'ENG')
昔日梦未散 2025-02-08 05:19:01

您可以利用IFERROR函数以这样的方式,如果搜索框具有字母顺序值,则将搜索图库以获取文本类型列,但是如果搜索框具有数值,则将搜索图库以获取数字类型列。

iferror(
过滤器(dataSource,numerictypepecolumn = value(searchbox.text)),
过滤器(DataSource,StartSwith(TextTypeColumn,searchbox.text))

我更喜欢使用startswith函数而不是搜索功能。

You can utilize Iferror function in such a way that if the searchbox has an alphabetical value then the gallery would be searched for text type columns but if the searchbox has a numerical value then the gallery would be searched for the numeric type column.

IfError(
Filter(DataSource,NumericTypeColumn=Value(SearchBox.Text)),
Filter(DataSource,StartsWith(TextTypeColumn,SearchBox.Text))
)

I prefer to use Startswith function instead of Search function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文