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

Add a sort by date option to the browse screen

Hi there,

 

I have a simple data set showing on the browse screen of my app that already has the default sort ascending descending button, the OnSelect command is UpdateContext({SortDescending1: !SortDescending1}).  I have a text field on the screen that shows the date and time a record was added via the EditScreen and I would like to add a button to allow users to sort by date and time.

 

The text field that holds the date is named "Body1", so I tried putting "UpdateContext({SortAecending:Body1})" but I get a message saying there are side effects and it cannot be evaluated, does anyone have any advice for me?

 

Thanks,

Alan

13 REPLIES 13
Highlighted
Impactful Individual
Impactful Individual

Re: Add a sort by date option to the browse screen

Can you post a screenshot so we can see what exactly you’re referring to
Highlighted
Helper II
Helper II

Re: Add a sort by date option to the browse screen

Hopefully, the attached shows what I am trying to do...

Highlighted
Impactful Individual
Impactful Individual

Re: Add a sort by date option to the browse screen

Can you post your formula for the gallery items property
Also, you don’t want to refer to the control name but instead the field name in the table such as ‘date’.
I would do this:
Original button OnSelect:
If(Sort1 = false || IsBlank(Sort1),Set(Sort1,true),Set(Sort1,false))
New button OnSelect:
If(Sort2 = false || IsBlank(Sort2),Set(Sort2,true),Set(Sort2,false))

Then gallery items:
If(Sort1 = false || IsBlank(Sort1),
If(Sort2 = false || IsBlank(Sort2),
DatasourceName,SortByColumns(DatasourceName,”datecolumn”,Ascending)),
If(Sort2 = false || IsBlank(Sort2),
SortByColumns(datasource,”FirstColumn”,Descending), SortByColumns(DatasourceName,”FirstColumn”,Descending,”datecolumn”,Ascending)))

You may need to switch round the columns in the very last part depending on what you want it to sort by first/second
Prob need to change the quote marks also as writing this on my mobile

Ps. You can use updatecontext instead of set but I like to use all my variables on multiple screens, updatecontext doesn’t roam whereas set does

I’ve also not applied any initial filtering to the data source and you may have to put this formula in a variable and set it after each on select(gone blank and can’t think if items property can be set like this without the pc in front of me), if so do:
Set(GalleryItems,Formulaabove) in the onselects after the set/sort formula above and then in your gallery items just put: GalleryItems
Helper II
Helper II

Re: Add a sort by date option to the browse screen

Hi Delid4ve,

 

Many thanks for providing such detailed help.  I am new to this and working on it in between other tasks so responses are slow - apologies.  I will look at implementing your suggestions this evening, meantime I don't see gallery items in the property list to send you the code from.  I built the app from an Excel file if that has any bearing on that?

 

Thanks again,

Alan

Highlighted
Community Support
Community Support

Re: Add a sort by date option to the browse screen

Hi @AlanR ,

 

Is this app auto-generated by PowerApps after you selecting Home > Start from your data? If so, then actually you can see how does the gallery being sorted and filtered, by selecting the gallery control and check its Items property:
Capture.JPG

 

In this screenshot, my BrowseGallery1 is sorted by "Days" column in my excel table. And search records that contain a string typed in search box in "Days" or "Name" columns.

 

If I want to sort with multiple columns, then I should change this formula to:

SortByColumns(Search([@Table1], TextSearchBox1.Text, "Days","Name"), "Days", If(SortDescending1, Descending, Ascending),"Name", If(SortDescending1, Descending, Ascending))

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper II
Helper II

Re: Add a sort by date option to the browse screen

Hi @v-monli-msft Mona,

 

Many thanks for the help and so sorry for the delay responding.  I am new to apps so all of this is a bit complicated for me! I did build the app from the Excel data source as you thought, when I click on the BrowseGallery1 the attached is what I see.

 

Ideally I want to retain the search box functionality, have the records sorted by my Excel table field "Date of Incident" shown under the Body1 control on the screen shot, and keep the alphabetic sort option under the current sort up down button.  How do I get rid of the "x0020" style references? Is there a consequence if I do?

 

Appreciate your time educating me on this,

Alan

 

 
Highlighted
Community Support
Community Support

Re: Add a sort by date option to the browse screen

Hi @AlanR ,

 

What is the column name inside your table? If it is Description of Issue, then you just need to use "Description of Issue" ( enclosed in double quotes) in the formula directly.

 

In which order do you want to sort with "Date of Incident" column? I assume that you want to sort with Descending, then you just need to replace the "If(SortDescending1, Descending, Ascending)" for this column to "Descending". For example, my formula should be:

SortByColumns(Search([@Table1], TextSearchBox1.Text, "Days","Name"), "Days", Descending,"Name", If(SortDescending1, Descending, Ascending))

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper II
Helper II

Re: Add a sort by date option to the browse screen

Hi Mona, @v-monli-msft 

 

I have made some progress with your advice, thank you but I am still struggling with what I think should be a simple sort of records on the browse screen by date.  My screen shot in the attached tries again to explain what I am hoping to do, can you review and let me know what you recommend?

 

Many thanks,

Alan

 

 

Highlighted
Helper II
Helper II

Re: Add a sort by date option to the browse screen

@mdevaney  Hi mdevaney - this thread is the sorting by date problem I mentioned in my other post - monli was very helpful but I was not able to figure out the solution suggested, (likely just me being thick), can you help or clarify?

 

Alan

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,906)