how to reset the gallery to default after I sort it in PowerApps?

Viewed 103

Sort button (OnSelect):

UpdateContext({sortGrade: !sortGrade})

Items in Gallery:

SortByColumns(Filter(
Search(
    Table1,
    TextInputSearch_3.Text,
    "Name2"
), "Cumulative Grade Point Average (CGPA)/Grade", If(sortGrade, Descending, Ascending))

Instead of it sort to ascending when the sortGrade is false, I want the gallery back to default arrangement, is it possible?

1 Answers

Luckily, I found an answer for my own question, so here it is for anyone that may encounters the same problem in PowerApps:

If(sortGrade=false,SortByColumns(Filter(
  Search(
   Table1,
   TextInputSearch_3.Text,
   "Name2"
   ), "Name2"),SortByColumns(Filter(
  Search(
   Table1,
   TextInputSearch_3.Text,
   "Name2"
   ),"Cumulative Grade Point Average (CGPA)/Grade", If(sortGrade, Descending)))

So when the sortGrade is false, the Gallery will be in the default arrangement (by Name2).

Related