Picking data from row of UDTable

Hi all,

Very new to PSU so please go easy. I’m using the latest and greatest version as far as I know.

My question is around a UDDynamic UDTable that I’ve created. I have UDButtons on each row of data which, when clicked, show me incorrect table data via $EventData via Show-UDToast.

The following is a code snippet, hopefully it’ll render correctly:


$Columns = @(
New-UDTableColumn -Property Name -Title “VM Name” -ShowSort -IncludeInExport -IncludeInSearch -ShowFilter -FilterType text
New-UDTableColumn -Property Guest -Title “OS” -ShowSort -IncludeInExport -IncludeInSearch -ShowFilter -FilterType text
New-UDTableColumn -Property PowerState -Title “Status” -DefaultSortColumn -ShowSort -IncludeInExport -IncludeInSearch -ShowFilter -FilterType select -Render {
New-UDElement -Tag ‘div’ -Attributes @{style = @{‘backgroundColor’ = $EventData.PowerColour; ‘color’ = ‘white’}} -Content { $EventData.PowerState }
}
New-UDTableColumn -Property PowerButton -Render {
New-UDButton -Id “btn$($EventData.PowerButton)” -Text $EventData.PowerButton -Icon (New-UDIcon -Icon $EventData.Icon) -IconAlignment left -OnClick {
Show-UDToast -Message $($EventData.Name) -Duration 10000
# Send Start-VM
}
}
)
New-UDTable -Id ‘vm_table’ -Data $newvms -Columns $Columns -Title ‘VMs’ -ShowSearch -ShowPagination -ShowSelection -Dense -PageSize 15


The table itself presents and updates itself beautifully, but whenever I click on any of the buttons in the last column, it gives me back $EventData from (I believe) the final parsed PSObject in the array, rather than data from the correct row.

Any pointers would be gratefully received. I’m having a lot of fun creating dashboards in PSU so far, so thanks very much for creating it!

Product: PowerShell Universal
Version: 2.0.0

It’s because you are setting the ID of the button. This is causing the last row’s to overwrite the previously set button. Try removing the -ID parameter on your button to see if that works better.

That was exactly it Adam, thanks very much! Now works as expected.

Have a good weekend.

1 Like