How to refresh table data asynchronously in the background?

Product: PowerShell Universal
Version: 4.4.0

Probably simple question but im struggling to get it right
I have a code that scans some share directory for subfolders (users profiles) and display results as a table

One of the columns is data size.
When there were few of those subfolders everything was fine page loaded quickly.

But now when there are few dozens and its growing this folder calculation take ages and page is loading like minute or so.

So how to display this table initially without size calculation , and then when all page content is rendered, run size calculation (it can be function, script, endpoint) and update this table (table is wrapped in uddynamic already) ?

It has to be done automatically not by hitting any button or something.

I would recommend looking into either the -LoadData [1] parameter of the table or transitioning into a DataGrid [2]. Let me know if I misunderstood the requirements but I believe these should do the trick.

Still the same maybe i dont understand it fully but code:


New-UDApp -Title 'PowerShell Universal' -Content {
    $Columns = @(
        New-UDTableColumn -Property "Name" -Title "Name"
        New-UDTableColumn -Property "Date" -Title "Date"
        New-UDTableColumn -Property "Size" -Title "Size"
    )

    $Data = Get-ChildItem '/security/images' -Directory | ForEach-Object {
    [PSCustomObject]@{
        Name = $_.name
        Date = $_.CreationTime
        Size = "" 
    }
    }

    New-UDTable -Columns $Columns -LoadData {
        $TotalCount = $Data.Count 
        $Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties 
        
    } -ShowFilter -ShowSort -Id 'table7' -RemoveCard -ShowRefresh 

    $folders = Get-ChildItem '/security/images' -Directory
    foreach ($folder in $folders) {
        $folder_size = (Get-ChildItem $folder -Recurse | Measure-Object -Property Length -Sum).Sum
        $folder_name = $folder.Name

        $data | ForEach-Object {
            if ($_.Name -eq $folder_name) {
                $_.Size = [math]::round($folder_size / 1MB, 2).ToString() + " MB"
            }
        }
    }
    Sync-UDElement -id 'table7' -Broadcast
}

waits for size calculation to display full table
if i wrap it in button then yes it will display table fast and then update table with size