New-UDTableColumn -Render New-UDSelect issue

I am having trouble with New-UDTableColumn -Render having New-UDSelect, the selections are showing however it does not update the actual value. The output still is set to the default value and not the one I selected on the New-UDSelect items. I am still new and learning so may be a problem with how I update or sync the udelement. Please help. Thanks.

$Columns = @(
New-UDTableColumn -Property CatalogName -Title CatalogName

                    New-UDTableColumn -id 'element_cloneimage' -Property CloneImage -Title CloneImage -Render {
                    $cloneimagevalue = $eventdata.CloneImage
                    $cloneimagename = $cloneimagevalue.name
                    $basetablefilter = $basetable | where {$_ -match $cloneimagename}

                            New-UDSelect -id Select_$($EventData.CloneImage) -Option {
                                                               
                                     foreach ($basename1 in $basetablefilter) {
                                        
                                        New-UDSelectOption -Name $basename1 -Value $basename1
                                     }
                                                              
                            } -DefaultValue $cloneimagename -OnChange {

                            Sync-UDElement -id 'element_cloneimage'
                            }
                        }

Any one care to answer my problem, I need this to work. Thanks in advance.

Anyone has an idea ?

Can you provide the rest of your code that has the New-UDTable?
What is the goal?

@jamir88 Is the goal to have a column in a table that only updates that specific row when a drop down selection is made?

@kevinblumenfeld that is correct. There is a defaultvalue set. But when I try to make a selection, it does not update the specific row, when I proceed to create the table, the row still contains the defaultvalue instead of the selection I made.

$Columns = @(
New-UDTableColumn -Property CatalogName -Title CatalogName

                    New-UDTableColumn -id 'element_cloneimage' -Property CloneImage -Title CloneImage -Render {
                    $cloneimagevalue = $eventdata.CloneImage
                    $cloneimagevalue = $cloneimagevalue.name
                    $cloneimagename = $eventdata.Baseimage
                    $basetablefilter = $basetable | where {$_ -match $cloneimagename}
                    $active_catalog = $eventdata.catalogname

                            New-UDSelect -id "Select_$($EventData.CloneImage)" -Option {
                                                               
                                     foreach ($basename1 in $basetablefilter) {
                                        
                                        New-UDSelectOption -Name $basename1 -Value $basename1
                                     }
                                                              
                            } -DefaultValue $cloneimagevalue -OnChange {
                            Sync-UDElement -Id 'Rollout'
                            Show-UDToast -Message "$EventData[0]"
                            ($mcupdatelist | where catalogname -eq $active_catalog).cloneimage = $EventData[0]
                            }
                        }

                    New-UDTableColumn -Id 'element_snapshot' -Property SnapShot -Title SnapShot -Render {
                    
                    $cloneimagevalue = $eventdata.Baseimage
                    $snapshottablefilter = $snapshottable | where name -match $cloneimagevalue
                    $active_catalog = $eventdata.catalogname

                            New-UDSelect -id "Selected_snapshot" -Option {
                                                                                               
                                     foreach ($baseinfo in $snapshottablefilter ) {
                                        $snapshotinfo = $baseinfo.name
                                        New-UDSelectOption -Name $snapshotinfo -Value $snapshotinfo
                                     }
                                                              
                            } -DefaultValue $eventdata.snapshot -OnChange {
                            Sync-UDElement -Id 'Rollout'
                            Show-UDToast -Message "$EventData[0]"
                            ($mcupdatelist | where catalogname -eq $active_catalog).snapshot = $Eventdata[0]
                            
                            }
                        }
                    New-UDTableColumn -Property BaseImage -Title BaseImage         
                    New-UDTableColumn -Property StorageResource -Title StorageResource
                    New-UDTableColumn -Property HostResource -Title HostResource
                    New-UDTableColumn -Property Engineer -Title Engineer 
                    )
                    New-UDTable -Id 'mcupdate_table' -Data $mcupdatelist -Columns $Columns -Title 'Clone and Snapshot Table' -ShowSearch -ShowPagination -ShowSelection -Dense -OnRowSelection {
                    $mcupdate_table = (Get-UDElement -Id 'mcupdate_table').selectedRows
                    $Item = $EventData
                    Show-UDToast -Message "$($Item | out-string)"  -Duration 10000
                    }
$Columns = @(
    New-UDTableColumn -Property CatalogName -Title CatalogName
    New-UDTableColumn -id 'element_cloneimage' -Property CloneImage -Title CloneImage -Render {
        $cloneimagevalue = $eventdata.CloneImage
        $cloneimagevalue = $cloneimagevalue.name
        $cloneimagename = $eventdata.Baseimage
        $basetablefilter = $basetable | where { $_ -match $cloneimagename }
        $active_catalog = $eventdata.catalogname

        New-UDSelect -id "Select_$($EventData.CloneImage)" -Option {
                                               
            foreach ($basename1 in $basetablefilter) {
                        
                New-UDSelectOption -Name $basename1 -Value $basename1
            }
                                              
        } -DefaultValue $cloneimagevalue -OnChange {
            Sync-UDElement -Id 'Rollout'
            Show-UDToast -Message "$EventData[0]"
            ($mcupdatelist | where catalogname -eq $active_catalog).cloneimage = $EventData[0]
        }
    }

    New-UDTableColumn -Id 'element_snapshot' -Property SnapShot -Title SnapShot -Render {
    
        $cloneimagevalue = $eventdata.Baseimage
        $snapshottablefilter = $snapshottable | where name -match $cloneimagevalue
        $active_catalog = $eventdata.catalogname

        New-UDSelect -id "Selected_snapshot" -Option {
                                                                               
            foreach ($baseinfo in $snapshottablefilter ) {
                $snapshotinfo = $baseinfo.name
                New-UDSelectOption -Name $snapshotinfo -Value $snapshotinfo
            }
                                              
        } -DefaultValue $eventdata.snapshot -OnChange {
            Sync-UDElement -Id 'Rollout'
            Show-UDToast -Message "$EventData[0]"
            ($mcupdatelist | where catalogname -eq $active_catalog).snapshot = $Eventdata[0]
            
        }
    }
    New-UDTableColumn -Property BaseImage -Title BaseImage         
    New-UDTableColumn -Property StorageResource -Title StorageResource
    New-UDTableColumn -Property HostResource -Title HostResource
    New-UDTableColumn -Property Engineer -Title Engineer 
)
New-UDTable -Id 'mcupdate_table' -Data $mcupdatelist -Columns $Columns -Title 'Clone and Snapshot Table' -ShowSearch -ShowPagination -ShowSelection -Dense -OnRowSelection {
    $mcupdate_table = (Get-UDElement -Id 'mcupdate_table').selectedRows
    $Item = $EventData
    Show-UDToast -Message "$($Item | out-string)"  -Duration 10000
}

thx having a look at it.

Did you see an example where New-UDTableColumn -ID 'Test' was being used with Sync-UDElement?

Also what version are you on?

No, I just experimented with different components because I could not figure out how to. Version is 3.9.5

@jamir88 I’m unsure if it’s possible to ascertain from which row a UDSelect is invoked. As of now, I haven’t stumbled upon a method to achieve this. That said, the -OnRowSelection feature might help. Additionally, while the sample code can shed some light, a visual representation—maybe in the form of a spreadsheet—showcasing your desired result before and after might be helpful. I used -LoadData, but feel free to stick to your approach. Since I frequently work with databases, I based my examples on them, using them as a template.


$Page:Data = foreach ($Item in (0..2)) {
    $Item = $Item.ToString()
    @{
        Col1 = $Item
        Col2 = $Item
        Col3 = $Item
    }
}
New-UDTable -Id 'Table' -LoadData {
    $TableData = ConvertFrom-Json $Body
    $Page:Data | Out-UDTableData -Page $TableData.page -TotalCount $Count.count -Properties $TableData.properties
} -Columns @(
    New-UDTableColumn -Property 'Col1' -Title 'Col1'
    New-UDTableColumn -Property 'Col2' -Title 'Col2'
    New-UDTableColumn -Property 'Col3' -Title 'Col3'
    New-UDTableColumn -Property 'CloneImage' -Title 'CloneImage' -Render {
        Show-UDToast ('$EventData {0}' -f ([PSCustomObject]$EventData | Select-Object *) | Out-String) -Duration 10000
        New-UDSelect -Id "Select_$($EventData.Col1)" -DefaultValue '3' -Option {                                                                               
            foreach ($Item in (3..9)) {  
                $Item = $Item.ToString() 
                New-UDSelectOption -Name $Item -Value $Item
            }                                  
        } -OnChange {
            Show-UDToast ('Was Selected with UDSelect:{0}. Row(s) Selected with checkboxes (Would need to be implemented): {1} ' -f $EventData[0], $Page:SelectedRows) -Duration 10000
            $Page:Data = foreach ($Item in $Page:Data) {
                @{
                    Col1 = $EventData[0]
                    Col2 = $Item.Col2
                    Col3 = $Item.Col3
                }
            }
            Sync-UDElement -id 'Table'
        }
    }
) -ShowSelection -OnRowSelection {
    $Page:Table = Get-UDElement -Id "Table"
    $Page:SelectedRows = $Page:Table.selectedRows
}

This post shows how to retrieve the UDSelect value from each selected row in a UDTable

Hope this helps.

@kevinblumenfeld thans for your suggestion. I am trying it out but no data was populating. Where did you get this data?

$TableData = ConvertFrom-Json $Body

Can you show me the content?

Can you provide code that you are trying. All data is there. It’s just sample numbers in $Page:Data