Update Table with Set-UDElement

Product: PowerShell Universal
Version: 1.4.6

I am trying to update a Table with Set-UDElement but I keep running into issues.

I verified in Debugging that values set correctly, but when I run the Set-UDElement command I get an error thrown:
Set-UDElement : Cannot process argument transformation on parameter ‘Properties’. Cannot convert the “System.Object[]” value of type “System.Object[]” to type
“System.Collections.Hashtable”.

Here is the section of code I am calling it from:

If ($EventData.Name -like ‘msn*’ -or $EventData.Name -like ‘cid*’) {

                 Wait-Debugger

                 $sn = ($EventData.Name).ToString()

                 $global:disks = Set-ServerInfo -Servername $sn

                 Set-UDElement -Id "ServerTable" -Attributes $global:disks

                 Show-UDToast -Message $sn -Duration 5000

             }

I verified that the $global:disks variable is an array of hashtables via the debugging method in VSCode.

image

This is the same type of input I used when building the Table with no issues.

You need to pass the attributes as a hashtable…Look how I am using it in this post:-

Thanks for the reply. Still struggling a bit though. I need to update the table data.

I’ve tried:

Set-UDElement -Id “ServerTable” -Attributes @{Data = $global:disks}
Set-UDElement -Id “ServerTable” -Attributes @{Value = $global:disks}
Set-UDElement -Id “ServerTable” -Attributes @{Properties = $global:disks}

I can’t quite figure out which attribute name to set with the new table value.

Hello @matthewy03 glad the reply helped a little…ok so you want to know what is in a table STATE that you can change…So I use firefox as my browser and I have installed this plugin:-

This allows me to inspect the REACT components on the page…so now if you install this and press F12 in the dashboard page you will see a REACT tab down the bottom. To make it easier give your ELEMENTS on the page an ID you will then see the component/element listed in here, clicking on the ID of the component then looking on th right hand side will show you all the PROPS and STATE for the component…As you are using Set-UDElement you need to look at the STATE and see the names of the ATTRIBUTES you can change in there…To make life easier, you can even type something new into one of the STATE attributes to see the desired effect straight-away.
I do cover what I have just typed here in the course I released just before xmas:-

If you are ever interested in building your own component from scratch.

Thanks for the help. Using the React extension I could see my element and the Properties.

Looks to me like the Data holds the values in the table, but it still won’t update when I use this:

Set-UDElement -Id “ServerTable” -Attributes @{Data = $cache:disks}
#cache:disks is a hashtable of values for the table
If I use Set-UD-Element -Id “ServerTable” -Attributes @{Title = “Test”}

I can see the Title change like it should- so I know the item is getting called and doing the right things, I just can’t seem to get the table values to update.

Thanks for screenshot. As the data is in an array thinking you will have to reference the array by index as in $data[1] if you get me. From the screenshot data looks like a 2 dimensional array

I think I was going down a rabbit hole there.

I figured out an easier way to do it by nesting the New-UDTable under a New-UDDynamic region, then calling sync-udelement to the dynamic ID. The table updates after that with the new values selected.

The only thing I need to figure out now is when the Table array only has 1 value I get a React Error.

When it has 2 or more values it seems to work as expected. This is also true when building a new table. seems it doens’t like just 1 array value.

The screen shot below is what it looks like when it has 2.

we fix the bug with the react error, but didn’t push the fixes I hope we will for the next release,
and for the workaround that you do with New-UDDynamic, you need to take into account that when you do that, every time the all table do a rerender, if your data is small it’s ok, but if your data is big and you are not using server-side you going to notice that every render is slower.
also every time that uddynamic render the table it also reset the filters and sorting.

also im currently working on this bug i found it, just do some testing to see if i fix its :slight_smile:

Sounds good. Thanks AlonGvili. I think I’m running into that bug so I’ll be awaiting that fix.
the Table data will be very small in nature, I do see it re-render and flash on the screen when it does this but it’s a split second and something I can live with.

I do have 1 more thing, The table data is loaded -OnClick from a tree view. The Table will be created on the right hand side of the screen, but the tree view might stretch for a while vertically, when scrolling through the tree view and clicking something I have to then scroll back up to view the table.

Is there any way I can get a scroll bar on the TreeView itself so we can scroll in the tree view but leave the page scroll in tact?

we will need to check that out

1 Like