Refresh a single row in a table

Product: PowerShell Universal
Version: 3.7.10

Just sharing this because I’m happy I figured it out.

I have a table that is populated with machine names in the first column. The second column I wanted an icon to show if the machine was currently up, and the third a button to refresh the second column, but only for that row.

    New-UDDynamic -id "dyn_Computers" -Content {
        if ($session:computers){
            $columns = @(
                New-UDTableColumn -property Name -Title "Name" -DefaultSortColumn
                New-UDTableColumn -property online -Title "Online" -Render {
                    New-UDDynamic -id "dyn_Up_$($eventdata.name)" -Content {
                        If (Test-Connection $eventdata.name -Count 1 -Quiet){
                            New-UDIcon -Icon sith -Style @{
                                backgroundColor = "green"
                            }
                        }
                        else {
                            New-UDIcon -Icon sith -Style @{
                                backgroundColor = "red"
                            }
                        }
                    }
                }
                New-UDTableColumn -property refresh -Title "Refresh Row" -Render {
                    New-UDButton -Text "Refresh Row" -OnClick {
                        sync-udelement -id "dyn_Up_$($eventdata.name)"
                    }
                }
            )
            New-UDTable -Data $session:computers -Columns $columns -showselection
        }
    } -LoadingComponent {
        new-udprogress -Circular
    }

I found that I needed to make the UDDynamic name unique to each row, so I had the dynamic ID include $eventdata.name, and then had the button refresh that UDDynamic with the specific name.

Thinking on it more I may have it only check to see if the machine is up on selection. As it is this could cause a lot of traffic if there are a lot of results.

Any suggestions on a better way to do it?

Is that new-udprogress for the entire table? If it is, I am pretty sure it is possible to show a progress for that specific row/cell/value on button refresh, would might be a good way to show the icon potentially changing as otherwise I imagine it just goes from red → green or vice versa.

Thanks for sharing this code btw! I love looking at examples. Maybe share a gif so we can see it in action?

So I modified it even more since I posted this morning

$columns = @(
                    New-UDTableColumn -property Name -Title "Name" -DefaultSortColumn
                    New-UDTableColumn -property online -Title "Online" -Render {
                        New-UDDynamic -id "dyn_Up_$($eventdata.name)" -Content {
                            If (Test-Connection $eventdata.name -Count 1 -Quiet){
                                New-UDIcon -Icon sith -Style @{
                                    backgroundColor = "green"                             
                                }
                            }
                            else {
                                New-UDIcon -Icon sith -Style @{
                                    backgroundColor = "red"
                                }
                            }
                        } -LoadingComponent {
                            New-UDProgress -Circular -Color blue
                        }
                    }
                    New-UDTableColumn -property refresh -Title "Refresh Row" -Render {
                        New-UDButton -Text "Refresh Row" -OnClick {
                            sync-udelement -id "dyn_Up_$($eventdata.name)"
                        }
                    }
                )
                New-UDTable -id "tbl_Computers" -Data $session:computers -Columns $columns -showselection -Dense -OnRowSelection {
                    $DoStuff
        } -LoadingComponent {
            new-udprogress -Circular -Color blue
        }

So I have the whole table in a dynamic that will show the loading icon as it pulls data, and then each row has a loading icon that shows as it pings that machine

When you say “row” I think you just mean a single cell, correct? What you have posted looks like only the table (initial load) and 2nd column (single value) will show a refresh after hitting the button. Looks great to me and I couldn’t think of a better way to accomplish it

autologon

Here is it in action. The icons will show green if the machine is online.

Yes, just the second column has the loading icon

Yea that looks awesome. And if you hit refresh only the one row will reload right?

Yeah. That was fun to discover. I had to name the UDDynamic of that specific column with the $eventdata.name for that row, then the button calls that to refresh. Handy when you are waiting for a machine to boot, or DNS to sync.