cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Super User
Super User

Re: Sort / Filter Gallery items using buttons/icons

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

2 REPLIES 2
Highlighted
Super User
Super User

Re: Sort / Filter Gallery items using buttons/icons

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

Highlighted
Kudo Kingpin
Kudo Kingpin

Re: Sort / Filter Gallery items using buttons/icons

@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)

 

Helpful resources

Announcements
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,592)