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

Check all gallery items that are visible after filtering and patch

Hi there.

 

Inside a power app I have a gallery retrieving data from a SP list. This SP list is filtered by 2 drop downs. Each gallery item has a checkbox (not connected to the list just placed inside each record). Outside of the gallery I have a checkbox which OnCheck has this:

UpdateContext({SelectAll:!SelectAll})

 

And each checkbox's default value is this: if(SelectAll, true, false).

 

So, as it is, you may select individual records from gallery but if you check the checkbox outside the gallery you select/deselect all. What i sadly noticed is this:

Even if i filter my gallery data, when I check the checkbox to select all records, then if i remove the filter, all records are selected regardless the filtering. Any ideas of how to check the checkboxes of only visible records?

 

Also, could someone provide with an example of how to gather all records for which the Checkbox1 (each record's checkbox) is checked and update these records in SP list by updating one or 2 columns?

 

Your help is much appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

@pm4698 If you need individual checkboxes to hold their own values, you cannot have just one variable to handle them. The variable to maintain the state must be together with the rest of the data related to that record. For this we use collections. If you already don't have one, you'll have to create a collection which will have all the other fields that came from your datasource plus one more to hold the value of this check box. In the OnCheck() and OnUncheck() you will set the value of this variable to true or false.

Now for the Select All check box, In the OnCheck() and Onncheck() you will have to Patch the check box variable of the entire collection to be true or false.

 

Hope this helps.

View solution in original post

9 REPLIES 9
CNT
Super User
Super User

@pm4698 just one question before I give you the solution. Can the users check or uncheck the checkboxes inside the gallery?

hi @CNT  and thank you for the prompt reply. Yes, users can select individual records or just select all. Issue when selecting all is that apparently if i filter gallery, then select all then remove filters, all items are selected and not the ones filtered and checked. So i need to limit the check all to only filtered gallery items and then patch only those

MichaB12
Helper II
Helper II

Hi,

 

You can try something like this to Patch the selected items in your gallery:

ForAll(Gallery.AllItems, If(ThisRecord.Checkbox.Value, Patch('SPlist', ThisRecord, {col:"newValue"})))

 

From what I understand and tested with the select all, I think this behaviour is normal because you didn't linked the Checkbox with the record, so each items displayed in gallery will be selected. If you add or remove item in this gallery, they will be all checked.

 

hope this helps

@pm4698 If you need individual checkboxes to hold their own values, you cannot have just one variable to handle them. The variable to maintain the state must be together with the rest of the data related to that record. For this we use collections. If you already don't have one, you'll have to create a collection which will have all the other fields that came from your datasource plus one more to hold the value of this check box. In the OnCheck() and OnUncheck() you will set the value of this variable to true or false.

Now for the Select All check box, In the OnCheck() and Onncheck() you will have to Patch the check box variable of the entire collection to be true or false.

 

Hope this helps.

View solution in original post

pm4698
Helper II
Helper II

Ok so on my app OnStart i created a collection like this:

ClearCollect(mycollection, AddColumns('SP List', "isChecked", false)). Then i changed my gallery datasource to read from mycollection

And the Patch button actually goes like this:

ForAll(RenameColumns(Filter(mycollection,IsChecked),"ID","EID"),Patch('SP List', Lookup('SP List', ID=EID), {Status: "Done"});

and after that i refresh my SP List and ClearCollect to create again my fresh mycollection.

 

This seems to work as for the multiple checks and patching. I have 2 remaining issues though:

 

1) Before going that way for each record i had individual patch buttons like this:

Patch('SP List', ThisItem, {Status: "Done"}); but now its not working because the button is in a gallery with datasource mycollection (sp list + new column) and the SP List doesn't contain the new custom column. Any ideas of how to overcome this, for individual gallery record patching?

 

2) How should i manage the select all to limit only the visible records (after filtering) of mycollection?

MichaB12
Helper II
Helper II

1) You can use lookup function to replace "ThisItem", you just need to find the row in your SP list that match ThisItem, you can do this with a common identifier between this item and your data source item, for example the ID column:

Patch('SP List', Lookup('SP List', ThisRecord.ID=ThisItem.ID), {Status: "Done"});

 

2) I don't know 

pm4698
Helper II
Helper II

@MichaB12  that worked like a charm thank you! Also @CNT  thank you for pointing to the right direction!

 

As for the select only visible, what i did is this:

My gallery is filtering data upon filters selection and it presents the correct data. So I copied the formula that shows the filtered data inside the gallery and pasted it in onCheck and in onunCheck of my main checkbox. Then inside the conditions instead of presenting the data, I used clearCollect to update mycollection with these specific SP List records and for those records to have isChecked true (and false in the onunCheck). Like that it worked like a charm!

 

Thank you everyone for being so helpful!

 

I have one last question though: When i do the patching for all checked records I do it like this:

ForAll(
    RenameColumns(
       Filter(
        mycollection,IsChecked
       ),
       "ID",
       "EID"
     ),
     Patch('SP List', Lookup('SP List', ID=EID), {Status: "Done"});
)

Now inside the forall and after the patch function I would like to run a flow I created taking the itemID from the loop.

 

I used to do it like this:

myFlow.Run(ThisItem.ID) but it's not working for a reason.

 

Any help on this last one?

 

pm4698
Helper II
Helper II

I managed to make this work like this: myFlow.Run(ThisRecord.EID).

 

Thank you everyone! Keep up the good work!

@pm4698 Glad to help !

 

Please remember to give a 👍 and accept the solution as it will help others in the future.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, 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!

Top Solution Authors
Top Kudoed Authors
Users online (1,667)