Thursday, November 21, 2024

PowerApps search a gallery with multiple unrelated keywords

Here's how to do it. On the Items of your gallery, add the following: 

Sort(

Filter(

yourDatasourceOrCollection,

IsBlank('SearchInputTextbox'.Text) ||

Sum( 

ForAll(

Filter( Split('SearchInputTextbox'.Text, " "), 

Len(Trim(Value)) > 0 

), 

Or( 

If(Value in Column1, 1, 0), If(Value in Column2, 1, 0), If(Value in Column3, 1, 0) 

),

 Value 

) > 0 ), 

// The following IF lets you toggle the sort between two columns. Put this on the OnSelect of your sort button: Set(varSort, "Value.Location.Value"); 

If( 

varSort = "Value.Column3.Value", 

Column3, 

Column1 

), 

varSortOrder // This variable is set by a sort button to toggle sorting ascending or descending. Add this code on the OnSelect of the sort button: Set(varSortOrder, If(varSortOrder = SortOrder.Ascending, SortOrder.Descending, SortOrder.Ascending)) )