Dynamically add new grid

Hey :slight_smile:

Im playing around with PSU, but are having some issues understanding the New-UDElement / Set-UDElement / New-UDDynamic

I got this simple PoC, where you can click a computer object:

$TestArray = @()
1..5 | ForEach-Object {
    $TestArray += [PSCustomObject]@{
        ID     = $_
        Client = "Computer-$(Get-Random)"
    }
}
New-UDDashboard -Title 'All clients' -Content {
 
    New-UDGrid -Container -Content {
        New-UDGrid -Item -ExtraSmallSize 6 -Content {
            $Columns = @(
                New-UDTableColumn -Property ID -Title "ID" -Hidden
                New-UDTableColumn -Property Client -Title "Client Name" -ShowFilter -ShowSort
                New-UDTableColumn -Property ClientButton -Title "View" -Render {
                    New-UDButton -Text "View" -OnClick {
                        Show-UDToast -Message $eventdata.ID
                        Sync-UDElement -Id 'ClientIDSelection' 
                    }
                }
            )
            New-UDTable -Data $TestArray -Columns $Columns -ShowSort -ShowFilter -PageSize 5 -ShowPagination -Dense
        }
    }
    
    New-UDDynamic -Id 'ClientIDSelection' -Content {
        $SelectedClientId = Get-UDElement -Id ClientIDSelection
        Show-UDToast -Message $SelectedClientId
        if ($null -ne $SelectedClientId) {
            New-UDCard -Title "Test123" -Content {
            }
        } 
    }
}

What i want to achieve is, that a new set of grids / cards appear below the client selection, but only once the View button have been pressed & the ID property is then forwarded, so i can use it for querying the data, based on the ID.

I hope you can help me :slight_smile:

Hi,

I think the possibility “OnRowExpand” of a table is enough.
There is a “UDDynamic” in which you can then query and display data. See picture. Eventdata.ID is the ID value of the row.

Hi Daniel,

Thanks for the code example :slight_smile:
But i need to add several things, based on the ID (New-UDCard, Grids, images, etc) - so i dont think it will do :slight_smile: