cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cooper33
Resolver III
Resolver III

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
RandyHayes
Super User
Super User

@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 below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@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 below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!


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

@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 below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

thanks for this post. This gave me the answer I was desperately looking for. Just as a short amendment to Randy's solution, I'd like to propose to remove the additional column right after sorting, so that the problem Randy outlines at the bottom of his/her post won't occur:

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

 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,844)