cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kudo Kingpin
Kudo Kingpin

Sort / Filter Gallery items using buttons/icons

I have a gallery with the following Items property

SortByColumns(Filter(Routing, (InitiatorText = _varUser.Email) && oStatus = 1), "Title", Ascending)

Outside of this gallery, I added column headers with up/down arrows.  How do I re-sort the gallery items? I tried:

Sort(GalleryName.AllItems, Title, SortOrder.Descending)

Data Source: SharePoint Online list 

Same with filter if user wants to filter the gallery using different values. I can do this by creating multiple galleries but wondering if it can be done with one gallery?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Hi @Tamras 

 

I would have your Up/Down Arrows Set a variable, then SortbyColumns on that.

I am going to assume you mean you have only one up/down sort arrow, not one for each column, please let me know if that's not the case, as we can do that however it will take a bit more code.

 

So your Up Arrow's OnSelect would be:

Set(SortAscending, true)

 

And your Down Arrow's OnSelect would be:

Set(SortAscending, false)

 

Then your formula becomes:

SortByColumns(
Filter(
Routing,
(InitiatorText = _varUser.Email) && oStatus = 1),
"Title",
If(SortAscending,
Ascending,
Descending,
//This sets default sort Order
Ascending
)

)

This way, if your user selects one of the options, it will change the SortByColumn to Ascend/Descend depending on what you've chosen,

 

Any trouble with this, let me know,

 

Cheers,

ManCat


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

5 REPLIES 5
Super User II
Super User II

Hi @Tamras 

 

I would have your Up/Down Arrows Set a variable, then SortbyColumns on that.

I am going to assume you mean you have only one up/down sort arrow, not one for each column, please let me know if that's not the case, as we can do that however it will take a bit more code.

 

So your Up Arrow's OnSelect would be:

Set(SortAscending, true)

 

And your Down Arrow's OnSelect would be:

Set(SortAscending, false)

 

Then your formula becomes:

SortByColumns(
Filter(
Routing,
(InitiatorText = _varUser.Email) && oStatus = 1),
"Title",
If(SortAscending,
Ascending,
Descending,
//This sets default sort Order
Ascending
)

)

This way, if your user selects one of the options, it will change the SortByColumn to Ascend/Descend depending on what you've chosen,

 

Any trouble with this, let me know,

 

Cheers,

ManCat


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

@iAm_ManCat  Thank you! It worked perfectly.

 

I set my variables on a button that navigates to the screen where below gallery is located

Set(_varSortBy, "Deadline"); Set(SortAscending, true);

Since I have multiple columns, I ended up with the following formula for my Gallery Items property:

SortByColumns(Filter(Routing, (InitiatorText = _varUser.Email) && oStatus = 1), _varSortBy, If(SortAscending, Ascending, Descending))

Above formula received delegation warning in _varSortBy so I just used nested if to work around it as I really only need 3 columns with sort option.

I added an icon on Title column with the following OnSelect property:

UpdateContext({SortAscending: !SortAscending, _varSortBy: "Title"})

Then changed the icon property to toggle between up/down:

If(SortAscending, Icon.ChevronDown, Icon.ChevronUp)

 

Frequent Visitor

I needed to sort a gallery by two columns; Document title and Document type (both ascending/descending). I also needed to filter those columns based on entries from previous selections. I began by creating a variable (sort1) and 2 buttons for each of the columns that would be sorted, one ascending and one descending. The buttons "on select" changed the value of the variable to 1,2,3 or 4 depending on the selected button. Set(sort1,1) etc...

If(
   Sort1 = 1, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'Document Type',Ascending),
   Sort1 = 2, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'Document Type',Descending),
   Sort1 = 3, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'File name with extension',Ascending),
   Sort1 = 4, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'File name with extension',Descending)
)

I know it isn't the most elegant format. 😇  Thanks again for the support the previous posts helped me figure out where to start!

Frequent Visitor

I need to apply this formula but I can't

 

Filter('MONITOREO Y CONTROL',StartsWith(TRANSPORTE,"TransportesX") Or StartsWith(TRANSPORTE,"TransporteY"), and Switch(SortColumnPref,"Modified",SortByColumns('MONITOREO Y CONTROL',SortColumnPref,If(SortColumnModified,Ascending,Descending))))

@msh242 
I wrote a step-by-step tutorial on how to change the sort direction and column of a gallery using buttons or icons.  I'll leave a link to it below.

Article: 'Power Apps Gallery Sort Controls'
https://matthewdevaney.com/power-apps-gallery-sort-controls/

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (86,065)