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

Checkboxes uncheck when re-sorting gallery

So I have a gallery with a bunch of items from a sharepoint list. Each item has a checkbox next to it. The point of the gallery is to be able to select a bunch of items and then click "checkout" which will take you to another screen. When you check a box, the item is added to "ShoppingCart" collection, and when you uncheck it, the item is removed from the "ShoppingCart" collection. 

 

The gallery is long and has over 200 items. So I have a search bar and some drop-down filters as well as a sort button that re-sorts it alphabetically or reverse-alphabetically. 

 

I noticed when I check a couple of boxes, then hit the re-sort button twice (so it goes back to the original order), the check boxes disappear. However, the items still appear in my list. When I go to checkout, the items are still there. It's also interesting, because when I check the same items again, the items are duplicated in the list. 

 

The gallery uses a SortByColumns(Filter(  as well as an if statement to determine how to display the gallery. The sort button only has the following code:

UpdateContext({SortDescending1: !SortDescending1})

SortDescending1 is just used in the If statement of the gallery to determine if its alphabetical or reverse alphabetical. 

 

The basic problem boils down to this: the boxes uncheck when I re-sort the list. Anyway to fix this so the buttons stay checked when the list is re-sorted? 

1 ACCEPTED SOLUTION

Accepted Solutions
CNT
Community Champion
Community Champion

@JimmyNeutron For your Gallery, you have a Items property which has the long list of over 200 items. The checkbox you have added is just a control that is inside the gallery but not really a part of this data and the value (whether it is checked or unchecked) in relation to each record is not stored anywhere. So, when you do anything that resets the gallery (in your case by changing the sort order), all the controls will go back to their default values and the default value for your checkbox is false (unchecked). That is why they all get unchecked. So, if you want to do such manipulations and maintain the state, the values of the checkboxes have to be stored somewhere.

For this we use Collections. So instead of directly setting the datasource in the Items property of the Gallery, we will create a collection and collect the data into this collection. We will also add a column (say isChecked) to this collection to hold the state (value) of each checkbox.

In the OnCheck and OnUncheck of the checkbox, we will set this isChecked to true or false.

We will also set the default property of the checkbox to ThisItem.isChecked.

This way the checkboxes will keep their state when kicked around.

 

Hope this helps!

View solution in original post

4 REPLIES 4
CNT
Community Champion
Community Champion

Hi @JimmyNeutron A small clarification. I suppose the checkbox is a item in the Gallery. If so, where are you storing the state of the checkbox corresponding to each item in the Gallery?

 

The checkbox is in the gallery. So each record has a check box next to it. 

 

I'm not sure what you mean by state of the checkbox. I see the checkboxes have OnCheck and OnUncheck actions. I just use those to edit the ShoppingCart list.

 

The checkbox seems to have an check and unchecked state, but I'm not sure if its possible in Powerapps to check the checkbox using another control. For example (unrelated to this), I'm not sure if its possible that a lone button is clicked and checks another separate checkbox. If it is possible, I feel like there might be a way to go through the ShoppingCart list to re-check all of the checkboxes. 

CNT
Community Champion
Community Champion

@JimmyNeutron For your Gallery, you have a Items property which has the long list of over 200 items. The checkbox you have added is just a control that is inside the gallery but not really a part of this data and the value (whether it is checked or unchecked) in relation to each record is not stored anywhere. So, when you do anything that resets the gallery (in your case by changing the sort order), all the controls will go back to their default values and the default value for your checkbox is false (unchecked). That is why they all get unchecked. So, if you want to do such manipulations and maintain the state, the values of the checkboxes have to be stored somewhere.

For this we use Collections. So instead of directly setting the datasource in the Items property of the Gallery, we will create a collection and collect the data into this collection. We will also add a column (say isChecked) to this collection to hold the state (value) of each checkbox.

In the OnCheck and OnUncheck of the checkbox, we will set this isChecked to true or false.

We will also set the default property of the checkbox to ThisItem.isChecked.

This way the checkboxes will keep their state when kicked around.

 

Hope this helps!

View solution in original post

JordanDeVan
Advocate I
Advocate I

I'm in agreement with @CNT. I had a similar issue where checkboxes were being wiped out when other checkboxes in the gallery were checked. Storing the checkbox values inside of a collection took care of the issue.  

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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
Top Kudoed Authors
Users online (2,202)