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
Highlighted
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
Highlighted
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.
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.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, August 21st at 8am PDT

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

SixthImage

Power Summit Australia 2019

August 20-23rd 2019

Users Online
Currently online: 142 members 3,852 guests
Please welcome our newest community members: