cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
neill_long
Level: Powered On

Sort list

I have a gallery which lists some items.  It gets the items from a collection.

 

I would like to sort the list in alphabetical order but have 'Not Listed' at the top, everything else below in order.

 

This is what i have in on the items property of the gallery:

 

SortByColumns(If(IsBlank(SearchBox.Text),Items, Filter(Items, (SearchBox.Text) in Title)), "Title",["Not Listed"])

Not sure if i am in the right tracks but any advice woud be great, thanks

 

 

Alistair

1 ACCEPTED SOLUTION

Accepted Solutions
OneThing
Level 8

Re: Sort list

HI Alistair,

 

One way you can do this, is to collect a default entry into the collection first and then Collect a sorted list of the remaining entries. This will mean that the Initial Entry will always be first unless you further Sort it.

 

 

An example from one of my Apps.

ClearCollect(
    StatusList,
    {Result: "All Status"}
);
Collect(
    StatusList,
    Sort(
        Distinct(RepairLines,'Job Status'.Value),
        Result,
        Ascending
    )
)

 

There may be better ways to do this but I've found this works well for me.

 

5 REPLIES 5
OneThing
Level 8

Re: Sort list

HI Alistair,

 

One way you can do this, is to collect a default entry into the collection first and then Collect a sorted list of the remaining entries. This will mean that the Initial Entry will always be first unless you further Sort it.

 

 

An example from one of my Apps.

ClearCollect(
    StatusList,
    {Result: "All Status"}
);
Collect(
    StatusList,
    Sort(
        Distinct(RepairLines,'Job Status'.Value),
        Result,
        Ascending
    )
)

 

There may be better ways to do this but I've found this works well for me.

 

Community Support Team
Community Support Team

Re: Sort list

Hi @neill_long,

Could you please share a bit more about the ["Not Listed"] that you mentioned within your formula?

Is it a column value within your Items data source?

I agree with @OneThing's thought almost. You could consider take a try with the following workaround:

Collect(NewItems, LookUp(Items, ColumnName ="Not Listed"));
Collect(
NewItems,
SortByColumns(Filter(Items, ColumnName <>"Not Listed"), ColumnName, Ascending)
)

Note: The ColumnName represents the Column used to store the "Not Listed" value, and you want to sort your Gallery items based on ColumnName.

Set the Items property of the Gallery control to following:

If(IsBlank(SearchBox.Text), NewItems, Filter(NewItems, (SearchBox.Text) in Title)

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
neill_long
Level: Powered On

Re: Sort list

Hi @v-xida-msft,

 

I have a list of stationery items stored in a sharepoint list.  I have pulled these into a collection in my app.  These are displayed in a gallery.  "Not Listed" is included in this list, if the item is not on the list, the user selects "Not Listed" and enters the details in a notes field.

 

What i would like is for the "Not Listed" appear at the top of the list, and the rest in alphabetical order, and any further additions to the list will be sorted.

 

I have on the OnStart:  ClearCollect(Items, 'Stationery Items')

 

Were would i add :

 

Collect(NewItems, LookUp(Items, ColumnName ="Not Listed"));
Collect(
    NewItems, 
    SortByColumns(Filter(Items, ColumnName <>"Not Listed"), ColumnName, Ascending)
)

thanks

Alistair

neill_long
Level: Powered On

Re: Sort list

Hi @v-xida-msft, @OneThing

 

Thanks very much for your replies, i actually came up with a very simple solution, i put a * at the start of Not Listed and it now displays at the top when sorted.

 

That'll work for me.

 

thanks

Alistair

OneThing
Level 8

Re: Sort list

Glad you are sorted.

 

Sometimes its easier to "Fix" the data than work with it.