This post is to show how to do the search and sort on a power apps gallery using a Choice Field.
In this example I am using Microsoft/Sharepoint List as the data source. I have added one Choice Column into the list 'ChoiceCol', with the values as shown below.
Once the apps is created, to use the Choice column as the Search field and sort field, we need to modify the Items property of the Gallery.
The default value is as below. This will do the Search and Sort based on the Title field.
SortByColumns(Filter([@AJList] ,StartsWith(Title, TextSearchBox1.Text) ) , "Title", If(SortDescending1, Descending, Ascending) )
To make the Search based on the Choice column, we can modify the value as below.
Change Title to ChoiceCol.Value
SortByColumns(Filter([@AJList] ,StartsWith(ChoiceCol.Value, TextSearchBox1.Text) ) , "Title", If(SortDescending1, Descending, Ascending) )
To make the Sort based on the Choice column, we can modify the value as below. Basically add a new column to the table (using AddColumns) with a new name and the values from the Choice field and then specify the newly added column as the column for sorting.
SortByColumns(AddColumns(Filter([@AJList] , StartsWith(ChoiceCol.Value, TextSearchBox1.Text)) ,"SortChoiceCol",ChoiceCol.Value) ,"SortChoiceCol", If(SortDescending1, Descending, Ascending) )
Feel free to point out if anything is wrong/missing in this post.
Thank you, it worked
ReplyDelete