Programmatically select/unselect rows from UDTable

Any idea how to programmatically alter which rows are selected in a UDTable (and have the table UI update)?

I tried using Get-UDElement and Set-UDElement with the selectedrows property, but it didn’t do anything.

Product: PowerShell Universal
Version: 3.5.5
1 Like

I have the same question

The way I solved this is how some others have suggested. Add some extra data to your table data to track a unique ID, and then use that ID to create a new checkbox, overriding the built-in checkbox.

$Reviewer = @(
    [PSCustomObject]@{
        'Mail' = 'john.doe@gmail.com'
        'Title' = 'CEO'
        'DisplayName' = 'John Doe'
        'CheckBoxID' = "CheckboxMyPage$(New-Guid)"
        'CheckBoxChecked' = $false
        'CheckBoxDisabled' = $false
    }
    [PSCustomObject]@{
        'Mail' = 'clark.kent@gmail.com'
        'Title' = 'Ordinary Guy'
        'DisplayName' = 'Clark Kent'
        'CheckBoxID' = "CheckboxMyPage$(New-Guid)"
        'CheckBoxChecked' = $false
        'CheckBoxDisabled' = $false
    }
)
$Columns = @(
	New-UDTableColumn -Property 'Include' -Title 'Include' -Render {
		$CheckboxChecked = $EventData.CheckBoxChecked
		$CheckboxDisabled = $EventData.CheckBoxDisabled
		New-UDCheckBox -ID $EventData.CheckBoxID -Checked:$CheckboxChecked -Disabled:$CheckboxDisabled
	}
	New-UDTableColumn -Property 'Mail' -Title 'Email Address'
	New-UDTableColumn -Property 'Title' -Title 'Title'
	New-UDTableColumn -Property 'DisplayName' -Title 'Name' -Hidden
)
New-UDStack -Direction 'column' -Spacing 2 -Content {
	New-UDTable -Data $Reviewer -Columns $Columns -ID $TableID -Dense
}
1 Like