New -Selection in New-UDTable in 1.5.0

Product: PowerShell Universal
Version: 1.5.0
Dashboard: 3.2.0

When row selecting is enabled, the $EventData in -OnRowSelected or Get-Element on the table do not return an “id” or anything like it as shown in the example. I am looking at variable values from the copy-paste of the code from https://docs.ironmansoftware.com/dashboard/components/data-display/table#selection. In the example. the gif shows id field returned.

What I want to do: I need that field/or any some way of passing an invisible column “id” to find out which fields are selected and delete selected fields from an MSSQL table. Now that I am thinking about it, I am not sure how to make the transition of the “table” id, to my record id. I am already passing the id value in the object that is passed to Out-UDTableData, and using that to make a delete button column using $EventData.id inside the New-UDTableColumn -Render. With the new table select, I was hoping to add the ability to select multiple rows and delete them at once with a “delete” button, but again at a loss as to how to get which rows are selected without making an ID row that is visible for my users. Appreciate any suggestions.

Thanks,
Dan

Can you share your table code? I think I understand what you’re saying but it would be helpful to visualize it with some script.

you can used Get-udelement on the table main id , when you do that you will get the all table object inside this object you will have SelectedRows property that holds all the selected rows

Here is a sample of what I am trying to do(with debug-psudashboard in place in onclick events). Note the id value passed to Out-UDTableData. This is accessible in $EventData in New-UDTableColumn.

New-UDDashboard -Title ‘Test’ -Content {

New-UDDynamic -id 'dyn-my-table-add' {

    $MyTableAddProperties = @{

        Title = 'Created Entries'

        PageSize = 10

        id = 'my-table-add'

        ShowPagination = $true

        Padding = 'none'

        ShowSelection = $true

        Dense = $true

        LoadData = {

            $MyTableProperties = $Body | ConvertFrom-Json

            $MyTableOutput = @(

                @{

                    id = 138

                    location = "chicago"

                    submit = $null

                    edit = $null

                }

                @{

                    id = 139

                    location = "new york"

                    submit = $null

                    edit = $null

                }

            )

            $MyTableOutput | Out-UDTableData -Page $MyTableProperties.page -TotalCount $MyTableOutput.Count -Properties $MyTableProperties.properties

        }

        Columns = @(

            New-UDTableColumn -Title "Location" -Property "location"

            New-UDTableColumn -Title "Comment" -Property 'comment'

            New-UDTableColumn -Title "Submit" -Property 'Submit' -Render {

                New-UDButton -Icon (New-UDIcon -Icon plus_square -Size lg) -Size small -Text "" -Variant outlined -id "my-button-submit-$($EventData.id)" -OnClick {

                    Invoke-UDJavaScript -JavaScript "document.getElementById('my-button-submit-$($EventData.id)').parentNode.parentNode.style.backgroundColor = 'green';"

                    Show-UDToast -Message "Submitted" -Duration 3000

                    Sync-UDElement -Id "dyn-my-table-add"

                }

            }

            New-UDTableColumn -Title "Delete" -Property 'Delete' -Render {

                New-UDButton -Icon (New-UDIcon -Icon Trash -Size lg) -Size small -Text "" -Variant outlined -id "my-button-delete-$($EventData.id)" -OnClick {

                    Invoke-UDJavaScript -JavaScript "document.getElementById('my-button-delete-$($EventData.id)').parentNode.parentNode.style.backgroundColor = 'red';"

                    Show-UDToast -Message "Deleted" -Duration 3000

                    Sync-UDElement -Id "dyn-my-table-add"

                }

            }

        )

        OnRowSelection = {

            $Item = $EventData

            Debug-PSUDashboard

            Show-UDToast -Message "$($Item | out-string)"

        }

    }

    New-UDTable @MyTableAddProperties

}

New-UDButton -Text "Get Selected Rows" -OnClick {

    $Table = Get-UDElement -id "my-table-add"

    $Rows = $Table.selectedRows

    Debug-PSUDashboard

    Show-UDToast -Message "$($Rows | out-string)"

}

}
Here is what the OnRowSelected returns (a random ID instead of what I passed to the Out-UDTableData) :

Here is what Get-UDElement on the table returns. No id at all:

the id it’s not random we generate this id base on the data on the row and we do that for the server-side because if we don’t do that when you select rows and move to the next page and come back to the page that has selected rows, the rows won’t be selected anymore.

that said, you should have seen the real id and the generated one as uid, I don’t know if its a bug but I need to check, and come back to you

BTW can you change from id to something else like dataId or anything else except id
and see if you get this property back

I have tested changing the id field to dataid, and I do not get the property back. Not shown in screenshot, but I do not get the property in the Get-UDElement as well

I tested you code and you are correct, the id won’t pass to $EventData, but when i change it to dataId and even if its not showing up in the object i can get the value to display in the toast notification, its weird.
i need to do more tests

Appreciate the prompt responses. I got around it for now by just displaying the ID field in the table.

Thanks!

1 Like