cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thutzler
Regular Visitor

Filtering and Sorting a gallery

I am new to PowerApps so please be patient with me.  🙂  I am working with a SharePoint list which is used for logging training sessions.  The gallery shows a record ID number called ID, a Text field called Skill, Created date, and Text Field called location.

 

I can search based on record ID number successfully.  For this I have the following in the Gallery Item:

If(IsBlank(TextSearchBox1.Text), Logs, Filter(Logs, TextSearchBox1.Text in Text(ID))) 

 

I want to also be able to Sort Ascending and Descending by ID field by clicking on the icon.

 

I have spent several days going over all the entries and trying out all the solutions (sort, sortby columns, ect., but everytime I try any of the solutions all the records disappear from my gallery.  What am I missing?  Any suggestion would be very appreciated.  

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

You'll want to use the SortByColumns function for that. The first parameter of that function takes a "table", which can be either a data source directly, or the result of any other expression that also returns a table. It turns out that your If expression does return a table (since you can set it to the Items property of the gallery), so you should be able to use something along the lines of:

SortByColumns(
    If(
        IsBlank(TextSearchBox1.Text),
        Logs,
        Filter(Logs, TextSearchBox1.Text in Text(ID))),
    "ID",
    If(sortDescending, Descending, Ascending))

Where "sortDescending" is a variable that you can toggle by setting the following expression in the ascending/descending icon:

UpdateContext({sortDescending: !sortDescending})

View solution in original post

2 REPLIES 2
CarlosFigueira
Power Apps
Power Apps

You'll want to use the SortByColumns function for that. The first parameter of that function takes a "table", which can be either a data source directly, or the result of any other expression that also returns a table. It turns out that your If expression does return a table (since you can set it to the Items property of the gallery), so you should be able to use something along the lines of:

SortByColumns(
    If(
        IsBlank(TextSearchBox1.Text),
        Logs,
        Filter(Logs, TextSearchBox1.Text in Text(ID))),
    "ID",
    If(sortDescending, Descending, Ascending))

Where "sortDescending" is a variable that you can toggle by setting the following expression in the ascending/descending icon:

UpdateContext({sortDescending: !sortDescending})

Yes!  That worked!

 

Thank you so much for your help.  I was on the right track looks like, but l the column I was trying to use wasn't acceptable.  When I saw what you had a light went off and I tried a different column and worked fine.  I even have it searching on one column and sorting on another which is ideal for my purpose!  Thank you for getting me back on track, and for your patience!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,042)