I have a Gallery with items from a CDS entity. It is filtered so it never shows all records. I have a Collection meant for those items.
Each template in the Gallery has a Checkbox with the following formulas:
OnCheck: Collect(Collection, ThisItem)
OnUnCheck: Remove(Collection, ThisItem)
Default: ThisItem in Collection
Outside of my Gallery I have a Deselect button with the following formula:
OnSelect: Clear(Collection)
Clicking it will also clear any checkboxes due to their default value.
Everything above works perfectly. Below is where it fails.
Also outside of my Gallery, I want a SelectAll button to collect all visible items in my Gallery into the same Collection. Once it has done that, all my checkboxes will show up checked appropriately due to their Default value being tied to their participation in the Collection.
I have read many other posts here. I cannot achieve this by:
- setting SelectAll.OnSelect = Set(varAllSelected, true)
- setting Checkbox.Default = If(ThisItem In Collection, true, varAllSelected)
because it is not enough to have the ✓ show up, it is not the value of the checkbox that puts the item in the collection but the action of checking it. So doing this doesn't add it to Collection.
I tried the following formula:
OnSelect: ClearCollect(Collection, Gallery.AllItems)
But I get an error on my Checkbox.OnCheck and Checkbox.OnUnCheck formulas, saying the item I'm trying to add to a collection is not of a compatible type.
Why is AllItems not the same type as ThisItem?
I've also tried using ForAll but I don't quite know how to use it.
My objectives:
1) How to add all items from a Gallery to a collection? (I don't care about columns, I want all columns added but I don't know and don't care what they are and I'd prefer not to have to list them all out.)
2) Will the above solution guarantee that I'm only collecting the visible items in the Gallery and not the whole set of records fron Entity Name? My Gallery is filtered:
Gallery.Items = Filter('Entity Name','Created by'.'Full Name' = User();'Full Name')
This is really doing my head in. Please and thank you to anyone who can help and much appreciated!