web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Gallery Search and Sor...
Power Apps
Unanswered

Gallery Search and Sort function

(0) ShareShare
ReportReport
Posted on by 776

Hi Experts,

 

I am using below formula 

 

SortByColumns(Filter([@'datasourcesharepointlist'], StartsWith(Title,SearchBox.Text)), "Title", If(SortDescending1, Descending, Ascending))

Now this is only working to sort on one column (title column)

 

How can i sort on other columns ?

 

AshishJaiswal_0-1623765113045.png

 

Categories:
I have the same question (0)
  • zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on at

    Instead of colum name in your gallery code use variable like "varColum"

    and onClick of your sorting arrow update the variable with columname using UpdateContext. So whichever sorting icon you click column name will be changed according

  • AshishJaiswal Profile Picture
    776 on at

    @zmansuri ,

     

    Hello,

     

    Thank you for replying to my post.

     

    Could you guide me how to write it. I am not a developer. I just learn from youtube and blogs  😃

  • zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on at

    Gallery:

    SortByColumns(Filter([@'datasourcesharepointlist'], StartsWith(Title,SearchBox.Text)), varColumn, If(SortDescending1, Descending, Ascending))

     

    Sorting Button Beside Name field:

    OnClick:

    UpdateContext({varSort :"Name"});
    UpdateContext({SortDescending1:!SortDescending1});

     

    Sorting Button Beside availability fields:

     

    OnClick:

    UpdateContext({varSort :"Availability "});
    UpdateContext({SortDescending1:!SortDescending1});

     

    In Short every time you click your sorting button beside field name. It will set the column name of that field in the variable varColumn

    So in your gallery code where right now you have written "Title", which is why it is sorted by title. It will be varColumn instead of Title. And varColumn will change with buttoin click

  • AshishJaiswal Profile Picture
    776 on at

    @zmansuri 

    Awesome this works but now I am running into a delegation issue of 500 items (My list has more than 3000 + items)

  • zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on at

    unfortunately delegation will be there when using SortByColumns with variables. You can try this:

    running different sorting based on condition. Like keep the code on sorting buttons same. But change your gallery code to this:

    If(varColumn="Name",
    SortByColumns(
    Filter([@'datasourcesharepointlist'], StartsWith(Title,SearchBox.Text)), "Name", If(SortDescending1, Descending, Ascending)),

    if(varColumn="Availability",

    SortByColumns(Filter([@'datasourcesharepointlist'], StartsWith(Title,SearchBox.Text)), "Availability", If(SortDescending1, Descending, Ascending))))

     

    and so on.. So instead of usinf variable directly in sorting logic. You are running different sorting logics based on condition.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard