PowerApps 搜索和排序画廊

huangapple go评论137阅读模式
英文:

Powerapps Search and Sort Gallery

问题

我有一个PowerApps应用程序,我已经在画廊的列上实现了排序,但现在的要求是还要能够在画廊的列中进行搜索。如何在下面的代码中添加"搜索"功能?

Switch(
locSortColumn,
"DataSource", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), DataSource, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"MfgrName", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), MfgrName, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"MfgrItemCode", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), MfgrItemCode, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"ProductNumber", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), ProductNumber, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"ProductDescription", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), ProductDescription, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"Created", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), Created, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"LastTrans", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), LastTransactionDate, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"LastSpend", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), Last12MonthSpend, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank()), Created, SortOrder.Descending)
)

请将上述代码替换为以下内容,以添加搜索功能:

Switch(
locSortColumn,
"DataSource", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in DataSource)), DataSource, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"MfgrName", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in MfgrName)), MfgrName, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"MfgrItemCode", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in MfgrItemCode)), MfgrItemCode, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"ProductNumber", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in ProductNumber)), ProductNumber, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"ProductDescription", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in ProductDescription)), ProductDescription, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"Created", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in Created)), Created, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"LastTrans", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in LastTransactionDate)), LastTransactionDate, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"LastSpend", Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in Last12MonthSpend)), Last12MonthSpend, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
Sort(Filter(KED_DistributorItems, KED_BrandItemId=Blank() && (TextInputSearch.Text in Created)), Created, SortOrder.Descending)
)

这将在原始的排序逻辑中添加了搜索功能,搜索文本来自名为TextInputSearch的输入框的文本。

英文:

I have a powerapps application that I have implemented sorting on columns of a gallery, but now the requirement is to also be able to search across the columns in the gallery. How do I add "Search" to the code below?PowerApps 搜索和排序画廊

Switch(
locSortColumn,
"DataSource", Sort( Filter(KED_DistributorItems,KED_BrandItemId=Blank()), DataSource, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"MfgrName", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), MfgrName, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"MfgrItemCode", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), MfgrItemCode, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"ProductNumber", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), ProductNumber, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"ProductDescription", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), ProductDescription, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"Created", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), Created, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"LastTrans", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), LastTransactionDate, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
"LastSpend", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), Last12MonthSpend, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()), Created, SortOrder.Descending)
)

答案1

得分: 1

是的,一旦需要实现搜索-过滤-排序,这些公式往往会变得混乱。

以下是一些帮助的想法:

  1. With() 函数可以在代码中重复使用相同的长表达式时帮助你,就像你的 Filter() 表达式一样。
  2. 你还可以通过在 Sort() 函数下嵌套 Switch() 来重构你的公式:Sort(Filter(...),Switch(locSortColumn,"Created",Created,...))
  3. 了解 委托 如何适用于你的数据源,因为你可以根据它进行一些微调。例如,对于 SharePoint,通常首选首先应用一些通用过滤以减少数据大小,然后进行搜索,最后对结果进行排序,但也可能存在不同的情况。
英文:

Yes, these formulas tend to get messy once you have to implement search-filter-sort.

Here are some thoughts to help you:

  1. The With() function can help you out in situations when the same long expression is being repeated in your code, like your Filter() expression.
  2. You could also restructure your formula by nesting the Switch() under Sort() function: Sort(Filter(...),Switch(locSortColumn,"Created",Created,...))
  3. Research how delegation works for your data source, since you could do some fine tuning based on that too. For SharePoint for instance, it is mostly preferable to first apply some general filtering to reduce the data size, then do the search and finally sort the results, but there can be different scenarios.

答案2

得分: 1

以下是翻译好的部分:

你可以尝试这种方式。

    Switch(
      locSortColumn,
      "DataSource", Sort( Filter(KED_DistributorItems,(KED_BrandItemId=Blank()) && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n)), DataSource, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      "MfgrName", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()&& (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), MfgrName, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      "MfgrItemCode", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()&& (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), MfgrItemCode, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      "ProductNumber", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), ProductNumber, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      "ProductDescription", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), ProductDescription, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      "Created", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), Created, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      "LastTrans", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), LastTransactionDate, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      "LastSpend", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), Last12MonthSpend, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
      Sort(Filter&&(textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))(KED_DistributorItems,KED_BrandItemId=Blank() ), Created, SortOrder.Descending)
    )

希望这对你有帮助。如果需要进一步的翻译或有其他问题,请随时提问。

英文:

You can try this way.

Switch(
  locSortColumn,
  "DataSource", Sort( Filter(KED_DistributorItems,(KED_BrandItemId=Blank()) && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n)), DataSource, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  "MfgrName", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()&& (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), MfgrName, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  "MfgrItemCode", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank()&& (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), MfgrItemCode, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  "ProductNumber", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), ProductNumber, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  "ProductDescription", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), ProductDescription, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  "Created", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), Created, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  "LastTrans", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), LastTransactionDate, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  "LastSpend", Sort(Filter(KED_DistributorItems,KED_BrandItemId=Blank() && (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))), Last12MonthSpend, If(locSortAscending, SortOrder.Ascending, SortOrder.Descending)),
  Sort(Filter&& (textbox.text in column 1 || textbox.text in column 2 || textbox.text in column...n))(KED_DistributorItems,KED_BrandItemId=Blank() ), Created, SortOrder.Descending)
)

huangapple
  • 本文由 发表于 2023年7月12日 21:56:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定