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

4 REPLIES 4
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 8

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.
Lappi
Level: Power Up

Thanks Re: Sort gallery with SP choice field on button click

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
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (7,331)