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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard