Can't get UDTable to Update

New to Powershell Universal so sorry if this is a dumb question.

I am trying to get a UDTable to update based off the selection of another Table via OnRowSelection.

New-UDTable -Title "Host" -Id 'vmhost_table' -Data $Hosts -PageSize 10 -ShowSearch -StickyHeader -ShowPagination -ShowSort -DisableSortRemove -ShowSelection -DisableMultiSelect -Columns $HostsColumns -DisablePageSizeAll -OnRowSelection { 
                Sync-UDElement -Id 'dyVpg'
                Sync-UDElement -Id 'vpg_table'
                }

New-UDDynamic -Id 'dyVpg' -Content {
    
    $SelectedVMHost = $(Get-UDElement -id 'vmhost_table').selectedRows.Name
    if ($SelectedVMHost) {
        $VMHost = get-vmhost -Name $SelectedVMHost
        $PortGroups = $VMHost | Get-VirtualPortGroup | Select Name, VirtualSwitch
        New-UDTypography -Text "$($PortGroups | Out-String)" -Id "typography4" -GutterBottom
        New-UDTable -Title "Network" -Id 'vpg_table' -Data $PortGroups -RemoveCard -Dense
    }

The UDTypography seems to update fine with the needed values as the selection is changed, but the UDTable just never updates past the original load of the data. Tried the Dynamic and the Table ID directly without success.

Appreciate any help that you can provide.

It’s an array but you’re processing it like a single item.

New-UDTable -Title "Host" -Id 'vmhost_table' -Data $Hosts -PageSize 10 -ShowSearch -StickyHeader -ShowPagination -ShowSort -DisableSortRemove -ShowSelection -DisableMultiSelect -Columns $HostsColumns -DisablePageSizeAll -OnRowSelection { 
                Sync-UDElement -Id 'dyVpg'
                Sync-UDElement -Id 'vpg_table'
                }

New-UDDynamic -Id 'dyVpg' -Content {
    
    $SelectedVMHostList = $(Get-UDElement -id 'vmhost_table').selectedRows | Select-Object Name

    $VMPortList = $SelectedVMHostList | Foreach-Object {
        $VMName = $_.Name
        $VMHost = get-vmhost -Name $VMName
        $PortGroups = $VMHost | Get-VirtualPortGroup | Select Name, VirtualSwitch
        $PortGroups | ForEach-Object {
            [pscustomobject]@{
                VMName          = $VMName
                PortName        = $_.Name
                VirtualSwitch   = $_.VirtualSwitch
            }
        }
    }

    if ($VMPortList) {
        # New-UDTypography -Text "$($PortGroups | Out-String)" -Id "typography4" -GutterBottom
        New-UDTable -Title "Network" -Id 'vpg_table' -Data $VMPortList -RemoveCard -Dense
    }

I tried updating the code but unfortunately still same behavior. The selection works initially to load the UDTable, but upon changing to a different selection, the UDTable will not update to reflect the new content. The New-UDTypography will however.

Okay so I think I’ve had similar issues like this, try changing -content to -endpoint on your new-uddynamic and let me know if that makes a difference?
Also you’re refreshing both dyVpg & vpg_table, but why not just dyVpg only since vpg_table is inside that it will be re-rendered anyway, probably no need for both and may also be introducing other complications.

My answer may not help actually here, I could have sworn I did this the other day but maybe it was a different component (possibly New-UDElement) and not New-UDDynamic, I’m just getting ‘endpoint’ is not a valid parameter now.

But I would say, I do think something might be broken possibly either in my setup or in the latest version with the dynamic content, I’ve had quite a few issues, and I’m just currently trying out this code from the docs for auto refreshing charts, and it just does not refresh or update at all, it loads once and thats it!

New-UDDynamic -content {
        $Data = 1..10 | % { 
            [PSCustomObject]@{ Name = $_; value = get-random }
        }
        New-UDChartJS -Type 'bar' -Data $Data -DataProperty Value -Id 'test' -LabelProperty Name -BackgroundColor Blue
    } -AutoRefresh -AutoRefreshInterval 1

EDIT:
I’m going to make sure its nothing in my environment (since im running on a NAS through a reverse proxy) and run a clean insteall of the MSI installer locally on my desktop where I’ve had this working before. Back in a mo

Yeah so I just did a clean install of 4.0.12 on my local pc using the MSI installer, I think this is a bug, the new ud dynamic refresh example in the above snippet just doesnt work at all. I’ll roll back to an earlier version and try to figure at what point it starts working again.

Edit:
Just tried on 4.0.2 - it’s the same

Edit 2:
Okay, rolled back to 3.9.17 and it’s working. urgh.

Unless something fundamental has changed and the documentation is outdated and I’m doing somehting wrong I think it’s a bug. I’ll get it logged in github.

Edit 3: Op, I never actually asked @rrspyder - what version are you running?

have the same issue with 4.1.4

In the past i do have problems with Dynamics that didnt show new data.

All my Dynamics looks like:

New-UDDynamic -Id 'BetriebLDIVerfahrenCardTypDyn' -Content {
    Get-LDITypen #-Renew
    #$Header = New-UDCardHeader -Title "Rollen"
    $Footer = New-UDCardFooter -Content {
        New-UDTypography -Text "Weitere Aufgaben:" -Id TypoVerfahrenTyp
    } -Id "BetriebLDIVerfahrenCardFooterTyp"
    $Body = New-UDCardBody -Content {
        New-UDTable -Id 'BetriebLDIVerfahrenTableTyp' -Data $Session:Schaltzentrale.DataVerfahrentyp -Columns $ColumnsVerfahrenTyp -Title 'Typen' -Dense -OnRowSelection {
            ## $Item = $EventData
            #Show-UDToast -Message "Ausgewählt: $($Item.Typ)" -id "ToastTyp001"
        } -ShowSelection -Paging -PageSize 3 #-ShowSearch -ShowPagination
    } -Id "BetriebLDIVerfahrenCardBodyTyp"
    $Expand = New-UDCardExpand -Content {
#...
    } -Id "BetriebLDIVerfahrenCardExpandTyp"
    New-UDCard -Body $Body -Footer $Footer -Expand $Expand -Id "BetriebLDIVerfahrenCardTyp" # -Header $Header
} -LoadingComponent {
    New-UDProgress -ProgressColor $ProgressColor
} 

with LoadingComponent i do have less problem :wink:

Unfortunately, the problem still exists. Just tested with version 4.2.7. As soon as an ID is added to the table within a dynamic region, the content is no longer updated. Is there a solution for this?

Adding Columns parameter should fix it.

$ColumnsVpg = @(
    New-UDTableColumn -Property VMName -Title "VM Name"
    New-UDTableColumn -Property PortName -Title "Port Name"
    New-UDTableColumn -Property VirtualSwitch -Title 'Virtual Switch'
)


New-UDTable -Title "Network" -Id 'vpg_table' -Data $PortGroups -RemoveCard -Dense -Columns $ColumnsVpg

My Table is with Columns parameter - the Table is not refreshing its data.

Here was my test code.

It seems to only work with Columns listed out and -LoadingComponent { New-UDProgress }

Seems like we have enough to make a repro.

Example:

New-UDDashboard -Title "Demo Test" -Content {

$Columns = @(
    New-UDTableColumn -Property Name -Title "Name" -ShowFilter
    New-UDTableColumn -Property Value -Title "Value" -ShowFilter
)

$ColumnsNofilter = @(
    New-UDTableColumn -Property Name -Title "Name"
    New-UDTableColumn -Property Value -Title "Value"
)

$Data = 1..10 | ForEach-Object {
  @{
      Name = "Record-$_"
      Value = $_ 
  }
}

New-UDButton -Text 'Get Filtered Data' -OnClick {
    $Element = Get-UDElement -Id 'filteredTable'
    Show-UDModal -Content {
        New-UDElement -Tag 'pre' -Content {
           $Element | ConvertTo-Json
        }
    }
}

New-UDTable -Id 'filteredTable' -Columns $Columns -LoadData {
    foreach($Filter in $EventData.Filters)
    {
        $Data = $Data | Where-Object -Property $Filter.Id -Match -Value $Filter.Value
    }

    $TotalCount = $Data.Count 

    if (-not [string]::IsNullOrEmpty($EventData.OrderBy))
    {
        $Descending = $EventData.OrderDirection -ne 'asc'
        $Data = $Data | Sort-Object -Property $EventData.orderBy -Descending:$Descending
    }
    
    $Data = $Data | Select-Object -First $EventData.PageSize -Skip ($EventData.Page * $EventData.PageSize)

    $Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties 
} -ShowFilter -ShowSort -ShowPagination -ShowSelection -DisableMultiSelect -Dense -OnRowSelection {
        Sync-UDElement 'dyNext'
        # Sync-UDElement 'selectedTable'
    }

New-UDDynamic -Id 'dyNext' -Content {
    $element = (Get-UDElement -id 'filteredTable').SelectedRows
    if (-not $element) {
        return
    }
    New-UDTable -Id "selectedTable" -Data $element -Columns $ColumnsNoFilter -Dense -RemoveCard

} -LoadingComponent {
    #Seems to be required to make selectedTable work
    New-UDProgress
}

}

Actual:
Removing -Columns $ColumnsNofilter and -LoadingComponent { New-UDProgress }

Selecting from filteredTable does not update the selectedTable.

New-UDDynamic -Id 'dyNext' -Content {
    $element = (Get-UDElement -id 'filteredTable').SelectedRows
    if (-not $element) {
        return
    }
    New-UDTable -Id "selectedTable" -Data $element -Dense -RemoveCard

}

Expected:
This should work.

Workaround:
Example code does work.

So is it planned for an upcoming update? This problem is extremely annoying for us. Thank you very much!

I ran into this recently, remove the -ID from your table so that PSU will auto-generate a random one. I don’t know which version this behavior changed in because I don’t remember it being the case before.