Forum Discussion

Stuart Anderson's avatar
Stuart Anderson
Copper Contributor
Nov 14, 2017

PowerApps Template Gallery List Default Sort Order

Hi Everyone... Im hoping this is a very easily solution.

 

Building a Power App and i have a Template Gallery Display List on a screen which defaults to show the Created as Ascending. Is it possible to have the default view to be descending?

 

I have added a sort button and works fine but i need to know if you can have the default sort to be descending based upon the created date without the sort button.

 

As you can see from image below its just straight OTB and nothing crazy.

  • mctriv's avatar
    mctriv
    Copper Contributor

    Stuart Anderson I have exactly the same problem, I've been applying SortByColumns in various ways but can't get it to work, if I have any success, or you do, please let me know!

    • Stuart Anderson's avatar
      Stuart Anderson
      Copper Contributor

      mctriv been a couple years since this post. I have learned a few ways of doing this one. The best way to learn this is actually using one of the OTB templates in PowerApps as they have the sort order functionality already built, you just set the default to ascending or descending and then hide the button to change it.

       

      Below are the Gallery formulas you could use;

      SortByColumns(Filter('ICT Service Requests', StartsWith(Title, TextSearchBox1.Text)), "Created", If(SortDescending1, Descending, Ascending))

       

      SortByColumns(Filter('ICT Service Requests', StartsWith(Title, TextSearchBox1.Text)), "Created", If(SortDescending1, Ascending, Descending))

       

      The above is OTB for the Items section of the Gallery which usually is connected to a button for sort however if you just change the SortByColumns to be the other way around it works great. The default cannot be changed without using the SortByColumns option.

       

      You will still need the button for the sort order as far as i have been able to work out which needs the onselect to be something like this.

      UpdateContext({SortDescending1: !SortDescending1})

       

      But then just set the button to not be visible once you have the default to how you need it.

       

      There may be a much more simple way of doing this though, but this is the quickest way i have found.

Resources