New-UDTable how to get column name and pass in value to Onclick?

I have a table that looks like this:

When the user clicks the New-UDChip, in the -OnClick event, I am trying to pass in the “SQL Server Name” value, but am not totally sure how to get this.

I was able to “duct-tape” the first value from that column with: $array = Get-UdElement -Id 'ServerNameColumn'; Show-UDToast -Message ($array.content[1].text), but the issue with this is that I am passing a specific value into the array and it only seems to retrieve the first value “dev”. Even If I switch the array index to 2, it will fail.

In your -Render script block for the TotalBlockTime column, you cna use $EventData to access that row’s data. You might need to store the variable in another one to avoid scoping issues.

New-UDColumn -Property TotalBlockTime -Render {
   $Item = $EventData
   New-UDChip -Text 'More Info' -OnClick {
         Show-UDToast $Item.SqlServerName

Ok so I tried sooooooo many different variations and I believe this will work. I think the scoping of $EventData was throwing me for a loop because I definitely tried $EventData.ServerName, but that did not work. I’ve been posting a lot of questions lately as I am currently on the 2 week trial and want to get something together to show the bossman so I can get some licenses so I appreciate all your help!

Would you mind explaining what exactly $EventData is? I’m using it in my dashboards quite a bit, but I feel like I don’t fully understand it. For example, I use quite a bit of if/else checks like this $EventData.CPU -gt 40 in order to evaluate each row. Should I be thinking of $EventData as a single object, but it has IDs in it so when I click a particular row it can return records similarly to if I was to write array[0].ServerName or array[1].ServerName?

Edit: kind of a continuation on my question and I haven’t tested this yet, but if I show a modal on a ud-chip click event, what is the context of $EventData at that point? Will it understand I am still referencing that same servername?

$EventData is the data that is related to the current event handler you are using. It differs depending on the type of event. For example, with a UDSwitch -OnChange, $EventData will be either $true or $false for that type of event. For a table -OnRender, it’s the current row. It won’t be an array but a hashtable\pscustomobject that contains one row of data.

The scoping matters because in your circumstance there are 2 event handlers in play. There is the -OnRender event handler in the outer scope and then the -OnClick event handler with inner scope. The reason you can directly use $EventData within the -OnClick in your example is because $EventData is being overwritten in the OnClick event handler by that handler’s data. In terms of a button click, the $EventData is actually $null.

1 Like

Following up on this thread… how would I get the column name (key value) of the datarow for the New-UDChip that a user selects. For example, in the image at the top, if a user clicked ‘More Info’ UDChip, I would want “TotalBlockTime (s)”. It seems that like you said an entire datarow is returned. Maybe I could set the UDChip ID to the column name during render and then grab that value when the user clicks?