Table not being generated

Product: PowerShell Universal
Version: 1.5.15

I’m trying to generate a table with some custom formatting based on the value of a cell but I cannot get it to render at all. I just get a blank page. Any idea how I can troubleshoot this?

Here’s the table code:

$Pages += New-UDPage -Name 'StatusTest' -Content {
    
    #Dynamic element to update only the table and not the whole page
    New-UDDynamic -Id 'StatusTableTest' -Content {

        #Retrieve content for table
        $Data = foreach ($File in (Get-ChildItem -Path C:\PSU\EnrolledStations -Filter *.json)) { 
                Get-content $File.fullname | ConvertFrom-Json | Select-Object Station, StoredCustomer, LastSeen, Build
        }

        #Resort table by the station number (converts str stattion to int)
        $Data = $Data | Sort-Object -Property {
            if (($i = $_.Station -as [int])) { $i } else { $_ }
        } -Descending

        #Create table
        New-UDTable -Title "Stations Status" -Headers @('Station','LastSeen') -Endpoint {
            $Data | ForEach-Object {
                $BgColor = 'green'
                $FontColor = 'white'
                if ((New-TimeSpan -Start $_.LastSeen -End (Get-Date).Minute) -gt 2 ){
                    $BgColor = 'red'
                    $FontColor = 'white'
                }

                [PSCustomObject]@{
                    Station = $_.Station
                    LastSeen = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $_.LastSeen }
                } 
            } | Out-UDTableData -Property @('Station','LastSeen')
        } 
    }
}

Here’s the value of $Data:

[
    {
        "Station":  "1",
        "Build":  null,
        "Source":  null,
        "Transaction":  "7feedfc8",
        "IP":  "10.69.9.1",
        "LastSeen":  "7/8/2021 5:00:04 PM",
        "StoredCustomer":  null
    },
    {
        "Station":  "2",
        "Build":  null,
        "Source":  null,
        "Transaction":  "45be9e9d",
        "IP":  "10.69.9.2",
        "LastSeen":  "7/8/2021 4:59:24 PM",
        "StoredCustomer":  null
    },
    {
        "Station":  "3",
        "Build":  null,
        "Source":  null,
        "Transaction":  "5c2446d1",
        "IP":  "10.69.9.3",
        "LastSeen":  "7/8/2021 4:58:34 PM",
        "StoredCustomer":  null
    }
]

It looks like you’re using the UDv2 syntax for the table. Check out the docs for v3 on how to do customer table rendering: Table - PowerShell Universal

@adam I saw that example but I couldn’t figure out how to address the rendering per cell instead of per column. Would you happen to have an example I can look at?

The render script block is called for each cell in the column specified so you can do something like this.

$Pages += New-UDPage -Name ‘StatusTest’ -Content {

#Dynamic element to update only the table and not the whole page
New-UDDynamic -Id 'StatusTableTest' -Content {

    #Retrieve content for table
    $Data = foreach ($File in (Get-ChildItem -Path C:\PSU\EnrolledStations -Filter *.json)) { 
            Get-content $File.fullname | ConvertFrom-Json | Select-Object Station, StoredCustomer, LastSeen, Build
    }

    #Resort table by the station number (converts str stattion to int)
    $Data = $Data | Sort-Object -Property {
        if (($i = $_.Station -as [int])) { $i } else { $_ }
    } -Descending

   $Columns = @(
    New-UDTableColumn -Property Station -Title 'Station' 
    New-UDTableColumn -Property LastSeen -Title 'Last Seen' -Render {
            $BgColor = 'green'
            $FontColor = 'white'
            if ((New-TimeSpan -Start $EventData.LastSeen -End (Get-Date).Minute) -gt 2 ){
                $BgColor = 'red'
                $FontColor = 'white'
            }

            New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $EventData.LastSeen }
    }
   )

    #Create table
    New-UDTable -Data $data -Columns $Columns
}

}

Ahh that’s the bit I was missing. Thanks for the quick reply @adam