I want to create Tabs Button inside a horizontal gallery.
Scenario:
Total Tabs - 7
Tab Names - Basic Info, Phone, Email, Chat, SSP, SNOW, Other Services
I want these Tabs Gallery Item Property to have a collection (colTabs) where records of which I need to add & remove based on conditions.
'Basic Info' Tab would always be in the colTabs collection.
However, now comes the conditions....
CONDITION 1
I have another collection (colSourceData) which hold the records as similar as the tabs, (i.e Phone, Email, Chat, SSP) via checkboxes
If the Checkbox is checked it's collecting the item in colSourceData collection and if it's unchecked then it removes it.
Likewise, I want to add & remove the tabs like below condition:
If 'Phone' is in colSourceData then add the Phone Tab to the colTabs collection or else remove.
So goes with Email, Chat & SSP.
CONDITION 2
If ColSourceData is not empty then add Other Services Tab to the colTabs collection or else remove if it's empty.
CONDITION 3
I have a form control where one of the Field (Ticketing Tool) is Choice Type with below choices...
SNOW - Client Instance - Managed By Client
SNOW - Client Instance - Managed By Ac
Remedy
Sales
TCORP
Other
Now If that Ticketing Tool Filed have value which start with 'SNOW', then the SNOW Tab would be added or if it's not then removed from the colTabs collection.
Hope you would be able to get my requirements and assist me on solving this situation. GREAT THANKS IN ADVANCE.
PLEASE HELP
Hi @WiZey ,
THANKS THANKS THANKS A LOTTTTT!!!!!!
For explaining all the things in details and through I understood the approach and made some changes but keeping your suggestions as base.
I was able to make a Dynamic Collection based on the subjected conditions and now I could use this collection to display the Tabs.
THANKS A LOT. ❤️
Alright, no problem. I'll try and explain as much as possible.
So you want to dynamically add and remove an item in your collection.
To put it shortly, "Collect()" create a new item whereas "RemoveIf()" delete an existing item. Assuming your "Name"-column is the identifying key, the code will look like this:
Collect(colTabs, {Name:"Tab"})
RemoveIf(colTabs, Name = "Tab"})
"RemoveIf()" gives a wider scope compared to "Remove()" and efficiently deletes ALL items corresponding to the given name, thus deleting possible duplicates.
Now to call those two functions, you will need to write some code in "OnChange" property of your controls.
"OnChange" is a property which is triggered everytime the value of the control is changed. For a text input, it is triggered when you change the text. For a check box, it is triggered when you check/uncheck it.
Assuming you've stored your tab's name inside "colSourceData", you will put the code below in the "OnChange" property of your checkbox:
If(Self.Value,
Collect(colTabs, {Name:ThisItem.Name}),
RemoveIf(colTabs, Name = ThisItem.Name)
)
Using "Self", the code will ask the parent control (the checkbox) about its value. If it's TRUE, it will create a new item using "ThisItem" which refer to the currently selected record of the collection. So to say, we're extracting the "Name" in "colSourceData" and create an item in "colTabs" with it.
Otherwise if it's FALSE, "RemoveIf()" will delete any record whose "Name" is equal to the name of the unchecked item.
Now to check if the selected value in your combo box starts with "SNOW". As I said earlier, you can use "StartsWith()" to check if a string starts with a text sample.
To add/remove an item depending if the selected value does start with "SNOW", add the code below in the "OnChange()" of your combo box:
If(StartsWith(Self.Selected.Value, "SNOW"),
Collect(colTabs, {Name:"SNOW"}),
RemoveIf(colTabs, Name = "SNOW")
)
Everytime you change the value of the selected item in your combo box, it will now check if its text starts with "SNOW" and then execute the appropriate function.
As for your second condition, it will require a simple little trick. Everytime your collection is changed, you need to check if it's empty. If it is, you create the new item "Other service".
However, a collection does not have a "OnChange" property. That's why you have to add this code everytime you've added/removed an item in your collection:
...
If(IsEmpty(colTabs),
Collect(colTabs, {Name:"Other Services"}),
RemoveIf(colTabs, Name = "Other Services")
)
This will check if your collection is empty, and add/remove the "Other Services" tab to correspond to the situation.
This is a quickly-thought solution, there may be some hidden mistakes there and there. Please try and see how it goes, I hope my answer was clear enough.
Hi @WiZey ,
Thanks for the response.
I would prefer the items to be added & remove dynamically in my colTabs Collections with 3 different conditions and also where do I put these conditions.
I mean that to which property within the powerapps.
I know I am a newbie and needs a better and clear understanding with the provided solutions.
My Mind doesn't Runs as faster as all experts like you, but I'll try to cope up. Thanks.
Hello @JatinSaini ,
Do you want to filter the gallery containing the "colTabs" with your icon, or do you want to dynamically add and remove items in your collection?
I suggest using a filter to hide/display the icons that does not check your condition, it should be simpler to maintain.
1. To hide/display an item depending on a check box:
Filter(colTabs,
LookUp(colSourceData, Name = colTabs[@Name]).Checkbox.Value
)
2. To hide a "default" item if your collection is empty:
Coalesce(
Filter(...),
Table({Name:"Other services"})
)
3. To display an item only if a textbox starts with "SNOW":
Filter(colTabs,
Or(Name <> "SNOW", StartsWith(TextBox.Text, "SNOW"))
)
Hope this was helpful to you. Don't hesitate to ask if you need more help.
WarrenBelz
146,771
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional