Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

PowerApps Gallery with Multiple toggle Sort Columns

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:
  • ImaKickUrAsh Profile Picture
    ImaKickUrAsh 51 on at
    Re: PowerApps Gallery with Multiple toggle Sort Columns

    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
    )

     

  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 143,591 on at
    Re: PowerApps Gallery with Multiple toggle Sort Columns

    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

     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard