web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / PowerApps Gallery with...
Power Apps
Answered

PowerApps Gallery with Multiple toggle Sort Columns

(0) ShareShare
ReportReport
Posted on by 51

Hello!

 

I have a canvas app with a gallery & have 3 different fields I need to allow the user sort ascending/descending like a toggle.

 

Gallery Items are from a collection named collTasks

 

Sample gallery with items:

Task

Age 

button onselect : Set(varAgeSort, Ascending, Descending)

StartDate 

button onselect : Set(varStartSort, Ascending, Descending)

UpdatedDate 

button onselect :

Set(varUpdatedSort, Ascending, Descending)

Task 123149/1/239/26/23
Task ABC348/15/239/20/23
Task UNO39/24/239/27/23

 

So far I've got:

 

SortByColumns(collTasks,

     If(!IsBlank(varUpdatedSort),"UpdatedDate","Age"),

          If(!IsBlank(varUpdatedSort), varUpdatedSort, varAgeSort),

     "StartDate",varStartSort)

 

basically trying to say that if the user has selected the Updated Sort button, sort by that column & in the order captured in the variable varUpdatedSort, and same with Age & then StartDate - but the data needs to be sorted in the order the user hits the toggles. meaning if they hit "Age" first then UpdatedDate second, then the sort order should be "Age", value in varAgeSort, "UpdatedDate", value in varUpdatedSort. but then if the user hits varAgeSort toggle again, the sort order should be "UpdatedDate", value in varUpdatedSort,  "Age", value in varAgeSort.

 

is there a better way to tackle this? any guidance would be most appreciated, thanks!

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    153,127 Most Valuable Professional on at

    Hi @ImaKickUrAsh ,

    Here is an idea for you to try - I have not addressed the Sort Order (other than to make it Ascending), but you could also use the same principle on it. Firstly, you need a Default Sort, so at screen OnVisible

    UpdateContext(
     {
     varSort1: "Age",
     varSort2: "StartDate",
     varSort3: "UpdatedDate"
     }
    )

    Now on each one of the buttons OnSelect (example below) use the desired field name in both places

    If(
     varSort1 <> "Age",
     UpdateContext(
     {
     varSort3: varSort2,
     varSort2: varSort1,
     varSort1: "Age"
     }
     )
    )

    then your Gallery Items

    SortByColumns(
     collTasks,
     varSort1,
     SortOrder.Ascending,
     varSort2,
     SortOrder.Ascending,
     varSort3,
     SortOrder.Ascending
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • ImaKickUrAsh Profile Picture
    51 on at

    Thank you @WarrenBelz  - beautiful solution! I added the ascending/descending handlers like this (on each button) :

    If(
     varSort1 <> "Age" || !IsBlank(varSortOrder1),
     UpdateContext(
     {
     varSort3: varSort2,
     varSort2: varSort1,
     varSort1: "Age" ,
     varSortOrder3: varSortOrder3,
     varSortOrder2: varSortOrder2,
     varSortOrder1: If(varSortOrder1 = SortOrder.Ascending,SortOrder.Descending,SortOrder.Ascending)
     }
     )
    ); 

     

    & added the varSortOrder# as the SortByColumns sort order in the Items property:

    SortByColumns(
     collTasks,
     varSort1,
     varSortOrder1,
     varSort2,
     varSortOrder2,
     varSort3,
     varSortOrder3
    )

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard