cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cooper33
Level 8

Sort gallery with SP choice field on button click

I have a gallery connected to a SharePoint list. I want to be able to click on column headers (buttons) on the list so that the data in that column will be sorted. This is working fine for Text and Date fields but not Choice. Here is how I am achieving the Text/Date fields

Gallery Items: 

SortByColumns(
    *...gallery filtering...*
    sortCol,
    If(
        sortOrder,
        Ascending,
        Descending
    )
)

Sort by Title, on button click:

UpdateContext({sortCol:"Title",sortOrder:!sortOrder})

I tried adding.Value to the sortCol in the line above but that didn't work. Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Sort gallery with SP choice field on button click

@cooper33 

For this to work, you will need to get the value of the Choice column in your data.

The way to do that is to AddColumns.

 

SortByColumns(
    AddColumns(*...gallery filtering...*, 
"txtChoice", yourChoiceColumn.Value), sortCol, If( sortOrder, Ascending, Descending ) )

Then for sorting on that choice column:

UpdateContext({sortCol:"txtChoice",sortOrder:!sortOrder})

One thing to keep in mind...If you have any place that you are referring to the Gallery.Selected that is tied to the datasource (i.e. an EditForm that the Item resolves back to Gallery.Selected) then you will need to remove the added column in that property so that it does not conflict with the datasource signature.

 

I hope that is helpful for you...

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

3 REPLIES 3
Super User
Super User

Re: Sort gallery with SP choice field on button click

@cooper33 

For this to work, you will need to get the value of the Choice column in your data.

The way to do that is to AddColumns.

 

SortByColumns(
    AddColumns(*...gallery filtering...*, 
"txtChoice", yourChoiceColumn.Value), sortCol, If( sortOrder, Ascending, Descending ) )

Then for sorting on that choice column:

UpdateContext({sortCol:"txtChoice",sortOrder:!sortOrder})

One thing to keep in mind...If you have any place that you are referring to the Gallery.Selected that is tied to the datasource (i.e. an EditForm that the Item resolves back to Gallery.Selected) then you will need to remove the added column in that property so that it does not conflict with the datasource signature.

 

I hope that is helpful for you...

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

PytByt
Level: Powered On

Re: Sort gallery with SP choice field on button click


@RandyHayes wrote:

@cooper33 

For this to work, you will need to get the value of the Choice column in your data.

The way to do that is to AddColumns.

 

SortByColumns(
    AddColumns(*...gallery filtering...*, 
"txtChoice", yourChoiceColumn.Value), sortCol, If( sortOrder, Ascending, Descending ) )

Then for sorting on that choice column:

UpdateContext({sortCol:"txtChoice",sortOrder:!sortOrder})

One thing to keep in mind...If you have any place that you are referring to the Gallery.Selected that is tied to the datasource (i.e. an EditForm that the Item resolves back to Gallery.Selected) then you will need to remove the added column in that property so that it does not conflict with the datasource signature.

 

I hope that is helpful for you...

 

 

 


Hi @RandyHayes 

Im a newbie powerapps developers, i need to know where is exactly i put those formula?


And, what is this? 

*...gallery filtering...*

 

Thanks.

Super User
Super User

Re: Sort gallery with SP choice field on button click

@PytByt 

In this particular case, @cooper33 was using a Gallery in the App and had an existing filter or other formula for the Items property of the Gallery.

So, the proposed formula was to go into the Items property of the Gallery and the "*...Gallery Filtering...*" was meant to be whatever was currently in that Items property before changing the formula.

 

I hope that is clear and helps you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
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

Demo Extravaganza Championship Voting Open

Voting Ends: October 30, 2019!

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

Top Kudoed Authors
Users Online
Currently online: 339 members 5,351 guests
Please welcome our newest community members: