cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
richag
New Member

Gallery sort by date with filtering

Hi,

 

I am new to Power Apps and I have a gallery which is displaying data from an online excel spreadsheet, with the help of youtube I have managed to be able to filter the data with the use of dropdown's as well as searching by title column with a text input 

 

How can I make it so if I click the sort icon next to the date heading, it will sort the gallery by date (ascending and if clicked again descending)? 

 

powerapps-screenshot1.JPG

 

powerapps-screenshot2.JPG

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @richag ,

On the OnSelect of the Icon, put this

UpdateContext({varSortD:!varSortD})

Now you need to wrap your code in this (If you have supplied text, I could have corrected it for you). At the start, put

Sort(

then at the end

,
Date,
If(
   varSortD,
   Descending,
   Ascending
))

I assume your field name is Date here.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

10 REPLIES 10
WarrenBelz
Super User
Super User

Hi @richag ,

On the OnSelect of the Icon, put this

UpdateContext({varSortD:!varSortD})

Now you need to wrap your code in this (If you have supplied text, I could have corrected it for you). At the start, put

Sort(

then at the end

,
Date,
If(
   varSortD,
   Descending,
   Ascending
))

I assume your field name is Date here.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

@WarrenBelz I did this but when pressing the sort icon, the gallery does not change

@WarrenBelz I have this Text(ThisItem.Date,"[$-en-GB]d/m/yyyy") as the date item, could this be preventing the sort ?

@richag ,

Can you please provide the full code you have used in both places in Text. This has to work if all assumptions I made are correct.

@WarrenBelz 

Sort(
Search(
If(
catdrop.Selected.Result ="All" And locdrop.Selected.Result = "-", Table1,

catdrop.Selected.Result = "All" And locdrop.Selected.Result <> "-",
Filter(Table1, Location = locdrop.Selected.Result),

catdrop.Selected.Result <> "All" And locdrop.Selected.Result = "-",
Filter(Table1, Category = catdrop.Selected.Result),

catdrop.Selected.Result <> "All" And locdrop.Selected.Result <> "-",
Filter(Table1, Category = catdrop.Selected.Result And Location = locdrop.Selected.Result)),


TextInput2.Text, "Title"),

"Date",
If(
varSortD,
Descending,
Ascending
))

Sort icon OnSelect = UpdateContext({varSortD:!varSortD})

 

@richag ,

Try this

Search(
   Sort(
      Filter(
         Tablel,
         (catdrop.Selected.Result = "All" || Category = catdrop.Selected.Result) &&
         (Locdrop.Selected.Result = "-" || Location = Locdrop.Selected.Result)
      ),
      Date,
      If(
         varSortD,
         Descending,
         Ascending
      )
   ),
   Textlnput2.Text, 
   "Title"
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz - chucks a load of errors with sort, search and filter argument 

@richag ,

I could not test that, but this should work

Sort(
   Filter(
      Tablel,
      (catdrop.Selected.Result = "All" || Category = catdrop.Selected.Result) &&
      (Locdrop.Selected.Result = "-" || Location = Locdrop.Selected.Result) && 
      (IsBlank(Textlnput2.Text) || Textlnput2.Text in Title)
   ),
   Date,
   If(
      varSortD,
      Descending,
      Ascending
   )
)

also note this is free-typed, so check for spelling/names etc - the syntax structure is valid if your values are.
Also note the in Filter (and Search) are not Delegable, so you will get a warning and this will not work on tables over 2,000 items.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

I figured it, by taking your original suggestion, but changing Sort to SortByColumns - it then worked, accepted your answer as it lead me to the solution

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (2,416)