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

Custom Sort Order with Sort Button

Hi there,

 

Nearing the completion of some apps. We have a Work Order app where I would like to sort a vertical gallery by a custom order. Example pic below:

 

Capture.PNG

 

Normally, I would have a sort button by the column header to change the sort column and sort direction with the following code:

 

Set(varSortColumn, "cscit_logdate");
Set(
    varSortDirection,
    If(
        varSortDirection = Ascending,
        Descending,
        Ascending
    )
)

 

 

For the priority column, I need a custom sort order (from low to urgent or reverse) and I am trying the following code with no success: 

 

 

Set(varSortColumn,"cscit_priority");
Set(varSortDirection,
If(
    varSortDirection="[""Urgent"",""High"",""Medium"",""Low""]",
    "[""Low"",""Medium"",""High"",""Urgent""]",
    "[""Urgent"",""High"",""Medium"",""Low""]"
    ))

 

 

Anyone have any ideas?

5 REPLIES 5
SBax
Impactful Individual
Impactful Individual

When using custom sorting you use SortByColumns as opposed to sort 

 

For example:

 

SortByColumns( List, "Column, [ "Choice1", "Choice2" ] )

 

For regular sorting it would be:

 

SortByColumns( List, "Column", SortOrder.Descending ) *or SortOrder.Ascending*

 

Please try removing your sort formulas and replacing with SortByColumns instead 

cscit
Regular Visitor

I am already using SortByColumns. Code snippet below for Gallery Items:

 

   SortByColumns(
        Search(
            Filter(
                'Work Orders',
                Month('Log Date') = ddMonth.Selected.ID
            ),
            inpSearch.Text,
            "cscit_description"
        ),
        varSortColumn,
        varSortDirection
    )
SBax
Impactful Individual
Impactful Individual

Just noticed some extra brackets

 

Try this

 

Set(varSortColumn,"cscit_priority");

Set(varSortDirection,

If(

    varSortDirection=["Urgent","High","Medium","Low"],

    ["Low","Medium","High","Urgent"],

    ["Urgent","High","Medium","Low"]

    ))

cscit
Regular Visitor

No dice. It seems confused on the quotation marks (even after I removed the extra one around "Medium"). When I set a label to varSortDirection I get the error "Expected Text Value" with that code. With the code in my original post, I get the expected text value, but the sorting doesn't work right.

SBax
Impactful Individual
Impactful Individual

I think the variables might be part of the problem

 

Can you try stripping your items property back to have it sorting using the method described in this blog post

 

i.e hardcode your variables to see if it workst hat way. I note in both the blog post and the official documents, there is a space between the [ and the first " as well as the last " and the ]

 

The aim is to pass a table (i.e. not a string) into your second property (sort direction) containing the values you want to sort by, in order

 

I'm heading to bed, but will check back tomorrow on your progress, and try to replicate your issue 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (3,430)