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

Filtering with a toggle and sorting

Hello, I'm quite new to Powerapps and am attempting to make something here....

 

I'm working with an Orders list in Sharepoint for my App.  For my gallery I've added a toggle that would hide delivered orders by changing the items value to :

 

If(
Toggle1.Value = false,
Filter(
TruckList,
Status.Value = "Delivered"
),Filter(TruckList,Status.Value <> "Delivered"))

 

By doing this I've broken the included sort icon(ascending/descending), it no longer does anything.  I also don't want to sort by Title, I'd like to sort by DEL_DATE or STATUS.  If I could give the option of sorting by either of those as a 2nd toggle that might be ideal.

 

I tried Using SortByColumns in the [if] statement above but it just broke things, I'm not sure the syntax when working with the filter / toggle I already have in there

 

Perhaps a toggle isn't the best way to achieve this and that's why im struggling to find similar solutions to work from.  Any ideas?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Filtering with a toggle and sorting

Hi @jpage,


From your description, it appears that your datasource is a Sharepoint list and that one of the Columns in the list is Status. Also from your description, it appears that Status is a Choice or Lookup column. It appears that the Toggle is outside of the gallery. I am assuming that you want the Gallery to actively toggle between showing items that have been Delivered and those that have not been Delivered. To do that, I would use the UpdateContext() function to create a variable that is an alias for your filter condition as follows in the formula box below

Toggle properties
OnCheck - UpdateContext({delstatus: Filter(TruckList,Status.Value = "Delivered")})
OnUncheck- UpdateContext({delstatus: Filter(TruckList,Status.Value <>"Delivered")})
TrueText- "Delivered"
FalseText-"Pending"

Gallery Items property-
Sort(delstatus,DelDate,Ascending)

Screen property
OnVisible - UpdateContext({delstatus: Filter(TruckList, Status.Value <>"Delivered")})
The code above will set a default for the Gallery when the screen opens to show undelivered items
The toggle will originally be set as false. Toggling it back and forth with toggle the gallery between Delivered and not delivered items.
The Gallery items will be set in order of Ascending delivery date. You can change Ascending to Descending if you prefer to see the latest delivery dates first.
Since it is a Sharepoint list, using "<>"  in the formula will trigger an error message to the effect that there is potential problem with delegation if your list is 2000 items. You can eliminate the error message by making the TruckList a collection ie. ClearCollect(colTruckList,TruckList) and adding that to the OnVisible property of the Screen
ClearCollect(colTruckList,TruckList); UpdateContext({delstatus: Filter(colTruckList,Status.Value <> "Delivered")})
and then replacing "TruckList" in all the formulas in the first box with "colTruckList".

View solution in original post

5 REPLIES 5
Super User
Super User

Re: Filtering with a toggle and sorting

Hi @jpage,


From your description, it appears that your datasource is a Sharepoint list and that one of the Columns in the list is Status. Also from your description, it appears that Status is a Choice or Lookup column. It appears that the Toggle is outside of the gallery. I am assuming that you want the Gallery to actively toggle between showing items that have been Delivered and those that have not been Delivered. To do that, I would use the UpdateContext() function to create a variable that is an alias for your filter condition as follows in the formula box below

Toggle properties
OnCheck - UpdateContext({delstatus: Filter(TruckList,Status.Value = "Delivered")})
OnUncheck- UpdateContext({delstatus: Filter(TruckList,Status.Value <>"Delivered")})
TrueText- "Delivered"
FalseText-"Pending"

Gallery Items property-
Sort(delstatus,DelDate,Ascending)

Screen property
OnVisible - UpdateContext({delstatus: Filter(TruckList, Status.Value <>"Delivered")})
The code above will set a default for the Gallery when the screen opens to show undelivered items
The toggle will originally be set as false. Toggling it back and forth with toggle the gallery between Delivered and not delivered items.
The Gallery items will be set in order of Ascending delivery date. You can change Ascending to Descending if you prefer to see the latest delivery dates first.
Since it is a Sharepoint list, using "<>"  in the formula will trigger an error message to the effect that there is potential problem with delegation if your list is 2000 items. You can eliminate the error message by making the TruckList a collection ie. ClearCollect(colTruckList,TruckList) and adding that to the OnVisible property of the Screen
ClearCollect(colTruckList,TruckList); UpdateContext({delstatus: Filter(colTruckList,Status.Value <> "Delivered")})
and then replacing "TruckList" in all the formulas in the first box with "colTruckList".

View solution in original post

jpage
Level: Powered On

Re: Filtering with a toggle and sorting

Thank you so much for the detailed explanation alongside the code.  This appears to work perfectly!  

 

My only question that remains is since I started this gallery using a template, it includes a sort icon on the top nav bar and a search box that no longer functions after these modifications.  While the sort is not critical to this app at all since it is now properly sorted, I am still curious how I would make use of it in this context.  The search could prove useful still though

Super User
Super User

Re: Filtering with a toggle and sorting

@jpage,

Did you decide to go with the collection of your list? Makes a difference in setting up the search.

jpage
Level: Powered On

Re: Filtering with a toggle and sorting

I have not yet.  If I use a collection, does that affect the ability to edit and create new records from the app?  I want to make regular edits and new records to the underlying sharepoint list from app.

Super User
Super User

Re: Filtering with a toggle and sorting

Hi @jpage,

If you are not using a collection and you wanted to restore full functionality to your Sort icon and Search box:

SortByColumns(Filter(delStatus, StartsWith(yoursearchcolumn, TextSearchBox1.Text)),"ColumntoSort", If(SortDescending1, Descending, Ascending))

Replace yoursearchcolumn with the  name of the column you want to search, ColumntoSort with the column you want to use to sort the list and TextSearchBox1.Text with the actual name of your Search box and don't forget to put .Text on the end of it.

 

If you use a collection for your gallery instead of the actual datasource, you would have to make a minor change to the Edit and Display form's Item property but all the functionality of those forms would remain intact. 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 167 members 2,106 guests
Please welcome our newest community members: