I am working on a filter checkbox to filter a grid list and i’m using the Sync-UDElement to update the grid list. After interacting with the checkbox elements a couple of times, the Sync-UDElement stops triggering. I’m not sure if this is the best route to what I want to accomplish but I was wondering if anyone else experienced this same issue? Also here’s a snippet of what I want to do:
Start-UDDashboard -Dashboard (
New-UDDashboard -Title "Service Status" -Content {
$Cache:Filter = New-Object System.Collections.ArrayList
$Cache:Data = @(
[pscustomobject]@{Platform = "Joey";Service="Joeys Bike";Status="Working"},
[pscustomobject]@{Platform = "Joey";Service="Joeys Car";Status="Working"},
[pscustomobject]@{Platform = "Bill";Service="Bill's Car";Status="Out of Service"},
[pscustomobject]@{Platform = "Bill";Service="Bill's Bike";Status="Working"},
[pscustomobject]@{Platform = "Susan";Service="Susan's Bike";Status="Working"},
[pscustomobject]@{Platform = "Susan";Service="Susan's Car";Status="Working"}
)
New-UDLayout -Columns 3 -Content{
#Platform Filter
New-UDCard -Title "Platform Filter" -Endpoint {
$Data = $Cache:Data
foreach ($Platform in ($Data.Platform | select -Unique)){
New-UDCheckbox -Id $Platform -Label "$Platform" -OnChange {
#If Checked
if ($EventData){
#Check if doesn't Exist
if ($Cache:Filter.IndexOf($Platform) -lt 0){
$Cache:Filter.Add($Platform)
}
}else{
#Remove if exists
if ($Cache:Filter.IndexOf($Platform) -ge 0){
$Cache:Filter = $Cache:Filter | ?{$_ -ne $Platform}
}
}
Sync-UDElement -Id FilterList
Sync-UDElement -Id GridServiceStatus
}
}
}
#List of Applied Filters
New-UDGrid -Id FilterList -Endpoint {
$Cache:Filter | % { [PSCustomObject]@{Filter = $_} } | Out-UDGridData
} -Headers @("Filter") -Properties @("Filter")
}
#Platform Grid List
New-UDGrid -Title "Service Status" -Headers @("Platform", "Service", "Status") -Properties @("Platform", "Service", "Status") -Endpoint {
$Data = $Cache:Data
#Filter if filter was provided
if ($Cache:Filter.count -gt 0){
$Data = $Data |? {$Cache:Filter.indexOf($_.Platform) -ge 0}
}
#Send Data out
$Data | Out-UDGridData
} -Id GridServiceStatus
}
) -Port 1000