cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GeethaSandra
Helper II
Helper II

I have a gallery with different colors for each record. Can I sort the gallery records based on the colors?

Below is how the gallery looks like. There are totally 6 colors which are repeating for every record.

GeethaSandra_1-1660246067550.png

 

 

May I know if I can use a sort button to sort these records based on the colors?

 

I'm using the below command to sort based the Status - label text (3rd field - Open, Settled, Unknown status)

Sort(LaborContractsGallary_1.AllItems, Label5.Text, Ascending)

 

But the records are not being sorted based on the status.

Kindly let me know any solutions to tackle the sort issue.

 

PS: This is the items property of the gallery - 

If(CountRows(Filter1_Collection)<>0,Filter1_Collection)

 

Thanks,

Geetha

1 ACCEPTED SOLUTION

Accepted Solutions
SBax
Impactful Individual
Impactful Individual

You need to use add columns to create an extra column in the Filter1_Collection for 'Status' using this formula: Coalesce(LookUp('SharePoint2', Subtitle6_1.Text in 'Supplier Code', Status), "Unknown status") (currently used to display the text in Label5)

 

See this link for guidance on use of the add columns function, or a summary below

 

AddColumns( Table, ColumnName1, Formula1 [, ColumnName2, Formula2, ... ] )

Where,

  1. Table = This is required that specifies the table to operate on.
  2. ColumnName(s) = This is also required. Name(s) of the column(s) to add. You must specify a string (for example, “Name” with double quotes included) for this argument.
  3. Formula(s) = This is required. Formula(s) to evaluate for each record. The result is added as the value of the corresponding new column. You can reference other columns of the table in this formula.

 

the item property of your gallery would then be set to an if statement to check if your button variable is true/false, similar to what I mentioned above, I think it would be like this:

 

If(varStatusSort =true,Sort(Filter1_Collection,Status,Ascending),SortFilter1_Collection,Status,Ascending))

 

I'm off to bed for the night, I will log back on tomorrow and support further if required

View solution in original post

12 REPLIES 12
SBax
Impactful Individual
Impactful Individual

Hi @GeethaSandra 

 

What is your datasource for this app?

 

Sorting by choice columns is a bit more complex, you can achieve it, but the approach is slightly different based on the datasource

 

 I have solutions for Dataverse and SharePoint, but please be aware that you will face a delegation warning, so these solutions will not work with large databases 

GeethaSandra
Helper II
Helper II

Hi @SBax the datasource for this app is Share Point. And we have data with less than 1000 records. 

SBax
Impactful Individual
Impactful Individual

Great, so delegation is not an issue, give me 10-15 mins to look out an example from an app I've built 

SBax
Impactful Individual
Impactful Individual

@GeethaSandra 

 

Apologies for the delay, I struggled to find one that was close enough to what you need, so pulled together a new sharepoint list, and used the same choices in a column within it

 

To switch between sorting by title and sorting by status via a button, follow these steps:

  • set onVisible Property of your screen to UpdateContext({varStatusSort:false})
  • Add a button outside of your gallery
  • In the onSelect Property, add this formula: UpdateContext({varStatusSort:!varStatusSort})
  • in the text property, add this formula: If(varStatusSort = true,"SortByTitle","SortByStatus")
  • In the items property of your gallery, add this formula: If(varStatusSort = true,Sort(StatusSort,'Choice Field'.Value,Ascending),Sort(StatusSort,Title,Ascending))

 

the outcome looks like this:

items sorted  by Choice Column, with button text "Sort by TItle"items sorted by Choice Column, with button text "Sort by TItle"Items sorted by title, with button text "sort by status"Items sorted by title, with button text "sort by status"

the result will be a button that allows you two switch between sorting by title, or by "Choice Field"

GeethaSandra
Helper II
Helper II

Hi @SBax , Thanks for the detailed explanation.

The issue with using the above solution is that I'm reading the status value from a different data source. i.e., my gallery is using 2 data sources. So, when I try to use LaborContractsGallery_1, I'm unable to read the "Status" column as it is coming from a different data source. 

 

As mentioned in the above post, I have used the below query to sort - 

Sort(LaborContractsGallary_1.AllItems, Label5.Text, Descending)

 

And below is the results of the sort - 

GeethaSandra_0-1660251378379.png

 

GeethaSandra_1-1660251454218.png

 

here,

V3 -> Open

V1 -> Settled

V2 -> Unknown Status

 

But, when I'm in preview mode, if I click on the sort icon, there is not change in the gallery items.

GeethaSandra_2-1660251530235.png

 

May I know where is the issue?

 

Thanks,

Geetha

 

   

 

SBax
Impactful Individual
Impactful Individual

Can you confirm how you are getting the status column (i.e. the formula from the text property of "Label5"?

 

Also can you confirm the formula in the items property of your gallery please?

GeethaSandra
Helper II
Helper II

Formula for getting Status value (Label5 value) -

Coalesce(LookUp('SharePoint2', Subtitle6_1.Text in 'Supplier Code', Status), "Unknown status")

I have all the statues in SharePoint2. But for those records with no status, I'm renaming it to "Unknown Status" using Power Apps.

 

Formula for Items property in Gallery - 

If(CountRows(Filter1_Collection)<>0,Filter1_Collection)

SBax
Impactful Individual
Impactful Individual

Can you confirm the formula that is used to generate Filter1_Collection please?

ClearCollect(
Filter1_Collection,
Filter(
'SharePoint1',
(SearchBar_1.Text in 'CM Code') && (SearchBar_2.Text in Supplier || SearchBar_2.Text in Title)
)
)

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 (2,438)