After changing the identation only, this is how your code folded up for me.
Thanks for the tip!
I’m using format on save in my VScode settings which is responsible for the indentation structure atm.
Formatting aspects aside, the results look pretty good. Thanks!
Just got around to running dashboard code myself and it worked great on 2.7.0
Had issues running on 2.9.0 though.
Thanks again for sharing.
@J-C –
Hi! Is it possible to exclude uncheck item? It seems to be added to the array, even when I uncheck the item.
@cn9ne Thanks for bringing this to my attention. I’m not really sure how to handle this.
Any ideas @psDevUK @adam ?
I"m running similar code to the above and getting the checked item hanging around longer than desired. A partial solution for me was to initialize
$Cache:CheckBoxElementArray = @{ }
after handling the checked event. The page seems to need a totally refreshed for the prior checked item to be totally forgotten. This is as far as I have gotten with the issue.
@cn9ne I got it to work by leaving $Cache:CheckBoxElementArray = @{ }
where it was and wrapping the $Cache:CheckBoxElementArray[$_.Id]
hashtable in an if/else
:
if ($CheckBoxElement.Attributes["checked"]) {
$Cache:CheckBoxElementArray[$_.Id] = @{
Checked = $CheckBoxElement.Attributes["checked"]
Name = $_.ProcessName
Id = $_.Id
Handles = $_.Handles
}
}
else {
$Cache:CheckBoxElementArray.Remove($($_.Id))
}
@J-C Sorry I’ve not been following this whole thread, just skimmed through it now, but, wouldnt you want to use $session instead of $cache? the reason being is that modifications to cache would apply for everyone, so if you get two people browsing the page at the same time and making similar modifications to the same items it could cause issues, while session is relevant to only the visiting user.
@insomniacc Yes, makes perfect sense that $Session: over $Cache: should be used.
@J-C Thanks the if block around setting the hashtable did the trick.
I’m new to UD and was unaware of $Session:
I really appreciate this response and the explanation. thanks!
No problem
More info can be found here: https://docs.universaldashboard.io/endpoints/custom-variable-scopes
Thanks @J-C.
Hi All -
One question, are you able to retain “checked” checkbox if you go to other pages? Example, my UDgrid has 10 pages - i checked one row in page 1 and go to page 2 check another row - when I go back to both page 1 and 2, both checked items are gone.
This is now the only issue I have, I created a page where user can delete a user from the application. However, whenever they checked a row, when they go to other page or thru filter and check another row, both are gone. The checkbox status kept in array is correct though.
I put a checkpoint where it will check the array, and set-udelement of the checkbox accordingly. But doesn’t seem to work. Any idea?
UPDATE:
Found a way to do this. Re-insert the object with updated field.
I would also highly recommend setting up an sql db behind your dashboard to pass through these values.
Depending on how you host, when your app pool recycles you’ll loose anything in cache/session, its a fresh start. It may not be an issue for you, but for me, I restart my app pool nightly to clear any memory usage from building up (because i’m hosting in IIS), I also push any major changes to be deployed (although most of my pages are endpoints dot sourced in so things change on the fly). The point is, any buttons/input people use, on click, write directly to the sql table, when pages are loaded, they read the values directly, everything is persistent regardless of cache/session. Not to say I don’t use either of those two, but i’m just selective with how and when.
This is how I did using icon, basically when you click it will rewrite the custom object and write result to an array.
If user wants to revert back, click the check button - it will remove data from array and update the custom object.
The checkbox bug:
The value of the checked items will still be stored in the hashtable even though they appear unchecked.
Hello sorry I haven’t chipped in on this…but have you tried using a switch component instead of the checkbox component to see if has the same issue? In essence a switch is a glorified checkbox…
Never thought of that.
But, the way I did with the icon, I’m using a [switch] to enable (disabled other icons) disable (change icon to checked). This worked.