I was able to do it without any nested gallery to maximize performance. However, the data would need to be flattened into one collection.
ClearCollect(
col_Flatten,
{
Type: "Category",
Label: "BMI",
Key: "BMI",
ParentKey: "",
Expanded: false,
Visible: true
},
{
Type: "Subcategory",
Key: "BMI|Overall",
Label: "Overall",
ParentKey: "BMI",
Expanded: false,
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 1",
ParentKey: "BMI|Overall",
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 2",
ParentKey: "BMI|Overall",
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 3",
ParentKey: "BMI|Overall",
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 4",
ParentKey: "BMI|Overall",
Visible: false
},
{
Type: "Subcategory",
Key: "BMI|Facilities",
Label: "Facilities",
ParentKey: "BMI",
Expanded: false,
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 5",
ParentKey: "BMI|Facilities",
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 6",
ParentKey: "BMI|Facilities",
Visible: false
},
{
Type: "Subcategory",
Key: "BMI|Others",
Label: "Others",
ParentKey: "BMI",
Expanded: false,
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 7",
ParentKey: "BMI|Others",
Visible: false
},
{
Type: "Dashboard",
Label: "Dashboard 8",
ParentKey: "BMI|Others",
Visible: false
}
)
Then the gallery structure and how it looks like:
Set the Items of the gallery: Filter(col_Flatten,Visible = true)
Set the Visible for each template container to its respective type
con_Dashboard Visible: ThisItem.Type = "Dashboard"
con_Subcategory Visible: ThisItem.Type = "Subcategory"
con_Category Visible: ThisItem.Type = "Category"
Set the Text for each text label to its respective label: ThisItem.Label
Set the OnSelect for Category (btn_Category) to control expand/collapse function:
//--------------------------
//COLLAPSE THE CATEGORY (L1)
//--------------------------
UpdateIf(col_Flatten, Key = ThisItem.Key, { Expanded: !Expanded });
//--------------------------
//FOR ALL EXPANDED SUBCATEGORIES (L2), HIDE THE DASHBOARDS (L3)
//--------------------------
ForAll(
Filter(
col_Flatten,
ParentKey = ThisItem.Key,
Expanded = true
) As Child,
UpdateIf(
col_Flatten,
ParentKey = Child.Key,
{
Visible: !Visible
}
)
);
//--------------------------
//HIDE THE SUBCATEGORIES (L3)
//IF COLLAPSING THE L1 ALSO COLLAPSING THE L2,
//UPDATE THE EXPANDED FIELD AS WELL
//--------------------------
UpdateIf(
col_Flatten,
ParentKey = ThisItem.Key,
{
Visible: !Visible
//Expanded: !Expanded
}
);
And finally, set the
OnSelect for Subcategory (
btn_Subcategory):
//--------------------------
//COLLAPSE THE SUBCATEGORY (L2)
//--------------------------
UpdateIf(col_Flatten, Key = ThisItem.Key, { Expanded: !Expanded });
//--------------------------
//HIDE THE DASHBOARDS (L3)
//--------------------------
UpdateIf(
col_Flatten,
ParentKey = ThisItem.Key,
{ Visible: !Visible }
);
Apologies if it's too long😅
Hope you're able to give it a try!
Cheers!