Trying to colorize individual values on UDtable

Product: PowerShell Universal
Version: 3.6.1

I’m trying to colorize certain fields depending on their values, however they’re just showing as System.Collection.Hashtable

Neither New-UDHTML or New-UDTypography work

        foreach($user in $users)
        {
            if($user.suffix -eq '[]')
            {
                $suffix = "None"
                
            }
            else
            {
                $suffix = ($user.suffix|convertFrom-json).length
            }

            if($user.tokens -eq 0)
            {
                $tokens = New-UDTypography -Text 'None' -Style @{ color = 'red' }
                #$tokens = "none"
                #$tokens = New-UDHTML -markup '<p style="color:red;"> None.</p>'
            }
            else
            {
                $tokens = $user.tokens   
                #bldfjslkafjldks             
            }

            @{
                Username = $user.userID
                Tokens = $tokens
                Suffixes = $suffix
            }
        }
    )
    $columns = @(
        New-UDTablecolumn -property Username -title 'Username'
        New-UDTablecolumn -property Tokens -title 'Tokens'
        New-UDTablecolumn -property Suffixes -title 'Suffixes'
    )
    New-UDTable -id 'UsersTable' -Data $array -columns $columns

The values come out as System.Collection.Hashtable:

image

You need to tell the table to render it as such using… -render

$columns = @(
    New-UDTablecolumn -property Username -title 'Username'
    New-UDTablecolumn -property Tokens -title 'Tokens' -Render {
        If ($Eventdata.tokens -eq 0) {
            New-UDTypography -Text 'None' -Style @{ color = 'red' }
        }
        Else {
            New-UDTypography -text $Eventdata.tokens
        }
    }
    New-UDTablecolumn -property Suffixes -title 'Suffixes'
)
New-UDTable -id 'UsersTable' -Data $users-columns $columns

Also not sure where $Array comes from in your example. I’m assuming you are assigning the entire scriptblock above where you define your columns to this variable, but it is unnecessary.

The reason why your code isn’t working is because New-UDTypography creates a object. The table doesn’t know how to display an object within a cell, unless you specify code on how to render it.

1 Like

Thanks! If I recall, way back in the early days of PoshUD you could just fill a collection with objects that have New-UDHTML properties and Out-UDTableData handled everything. Looks like I’ll have to relearn a few things now that I’ve picked it up again