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 Apps
Unanswered

Sorting a list

(1) ShareShare
ReportReport
Posted on by 350

I need to be able to sort a list. The way I did the sort is not the proper way. 

 

I added buttons to the fields I want to be able to sort. But when I scroll across the list the buttons I added don't scroll like the list.  

Here the sort function. 

 

UpdateContext({ctx_sort_column: "crb1a_form_no"}); //use the actual Logical Name of this field
UpdateContext({ctx_sort_order: !ctx_sort_order})
Categories:
I have the same question (0)
  • KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at

    Hi @rroque,

     

    Do you have the code where the sorting is applied please?

     

    I suspect that the ctx_sort_order variable is being used to toggle between SortOrder.AscendingSortOrder.Descending.


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Connect with me online.

  • rroque Profile Picture
    350 on at

    Yes it is. 

    Items

     

    SortByColumns(
       Search(
          OPTrack_FormsInventoryEnhancedTables,
          txtSearch.Text,
          FORM_NO, REQ_DATE, COMMENT
       ),
       ctx_sort_column,
       If(
          ctx_sort_order,
          SortOrder.Ascending,
          SortOrder.Descending
       )
    )
    Then each button uses this
    UpdateContext({ctx_sort_column: "crb1a_form_no"}); //use the actual Logical Name of this field
    UpdateContext({ctx_sort_order: !ctx_sort_order})
  • rzuber Profile Picture
    552 Moderator on at

    You can't have dynamic columns in the Sort() or SortByColumns() function. You will have to use an If() or Switch() logic to figure out which column to sort by.

     

    For example, using your formula you could change it to:

     

    SortByColumns(
     Search(
     OPTrack_FormsInventoryEnhancedTables,
     txtSearch.Text,
     FORM_NO, REQ_DATE, COMMENT
     ),
     Switch(
     ctx_sort_column,
     "crb1a_form_no",
     crb1a_form_no
     ),
     If(
     ctx_sort_order,
     SortOrder.Ascending,
     SortOrder.Descending
     )
    )

     

     

    However, I am not sure if you can assign columns like this.. You might have to do something like:

     

    With(
     {
     _records: Search(
     OPTrack_FormsInventoryEnhancedTables,
     txtSearch.Text,
     FORM_NO, REQ_DATE, COMMENT
     ),
     _sortOrder: If(
     ctx_sort_order,
     SortOrder.Ascending,
     SortOrder.Descending
     )
     },
     Switch(
     ctx_sort_column,
     "crb1a_form_no",
     SortByColumns(_records, crb1a_form_no, _sortOrder)
     )
    )

     

    I tested the first method, and it does allow you to assign the sort column in this way, so both methods should work.

     

  • rroque Profile Picture
    350 on at

    I can sort just fine. The problem is when I scroll the list to the right my sort buttons I added do not scroll along with the list.  

     

  • KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at

    Are the buttons within the gallery template cell?

    Do you have a screenshot?


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Connect with me online.

  • rroque Profile Picture
    350 on at

    I noticed on your first sortbycolumns function not all of the columns listed. 

    For example the column names here are not listed in the switch command above.  

    FORM_NO, REQ_DATE, COMMENT

     

  • rroque Profile Picture
    350 on at

    Here's what the list looks like when I scroll.

     

    rroque_0-1718720265465.png

     

  • rzuber Profile Picture
    552 Moderator on at

    If your buttons are not where they are supposed to be, then you need to set their position to the Gallery's X + the position of the column.

     

    as for your other comments.. I was just providing examples for you, using the formula you provided. I tested it in my own environment, and it worked.. and I figured you can figure out the rest from my examples.

  • rroque Profile Picture
    350 on at

    I added three buttons to sort on.  The list and the button don't line up 

    rroque_0-1718721615638.png

     

  • rroque Profile Picture
    350 on at

    I'm not sure I understand how to add to the gallery template cell.  

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 528

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 306

Last 30 days Overall leaderboard