Sorting a PowerApps gallery using search

How to filter the contents of a gallery by user entered search terms then sort results using a toggle button.

 

Sort PowerApps gallery with user entered search text

 The code below searches the Client data source using the user entered contents of TextSearchBox1. Client name column is searched. The results are sorted by the Date column in either descending or ascending order depending on the true/false value of the SortDescending1 variable. This variable is toggled by the user when the up/down arrow icon in the title bar is clicked.

Code in the Items property of the Gallery

SortByColumns(Search(Client, TextSearchBox1.Text, "ClientName"), "Date", If(SortDescending, Descending, Ascending))

 

Code to toggle SortDescending. Placed in the OnSelect property of the up/down arrow icon.

UpdateContext({SortDescending: !SortDescending})