cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tamras
Level 10

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




Don't forget to 'Mark as Solution' and 'Thumbs Up' those who deserve it!
2 REPLIES 2
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




Don't forget to 'Mark as Solution' and 'Thumbs Up' those who deserve it!
Tamras
Level 10

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
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 484 members 4,535 guests
Please welcome our newest community members: