Show Button if not null in table

Hey everyone,

It’s been a minute since last time I was in the forum. Hopefully one of you can give some pointers. Below is a code snippet where I’m trying to display button at the first column but based if column Note from same row is not null/empty. However, when page load I get an error (screenshot below). If I remove the If clause then is all good. Not sure if what I’m trying to do can be accomplished :slight_smile:

Thanks

if(-not($webcfgcomplastday -eq $null)){
            $ErrorsGridColumns = @(
                New-UDTableColumn -Property ID -Title " " -Render {
                    if(-not($EventData.Note -eq $null -or $EventData.Note -eq "")){
                        New-UDButton -Id "btn$($EventData.ID)" -Text "View" -OnClick {
                            Show-UDModal -Content {
                                $preHTML = $($($EventData.Note) -replace "`n","<br>")
                                New-UDHtml -Markup "<div>$preHTML</div>"
                            } -Footer {
                                New-UDButton -Text "Close" -OnClick {Hide-UDModal}
                            }
                        }
                    }
                    
                }
                New-UDTableColumn -Property Task
                New-UDTableColumn -Property Status
                New-UDTableColumn -Property StartDate
                New-UDTableColumn -Property EndDate
            )
    
            New-UDTable -Id 'errors' -Data $webcfgcomplastday -Columns $ErrorsGridColumns -Title 'Latest Errors' -ShowPagination -Dense -PageSize 3 #-PageSizeOption @(5,10,20)
        }
        else{
            New-UDTypography -Text "No script errors found!" -Variant h4 -Align Center -Style @{color = 'green'}
        }

Product: PowerShell Universal
Version: 1.5.16

This is a bug and I’ll open an issue for it but you can work around it by making sure to return something from render. It seems to happen when nothing is returned. Here’s an example.

    $ErrorsGridColumns = @(
        New-UDTableColumn -Property ID -Title " " -Render {
            if(-not($EventData.Note -eq $null -or $EventData.Note -eq "")){
                New-UDButton -Id "btn$($EventData.ID)" -Text "View" -OnClick {
                    Show-UDModal -Content {
                        $preHTML = $($($EventData.Note) -replace "`n","<br>")
                        New-UDHtml -Markup "<div>$preHTML</div>"
                    } -Footer {
                        New-UDButton -Text "Close" -OnClick {Hide-UDModal}
                    }
                }
            }
            else 
            {
                ""
            }
        }
        New-UDTableColumn -Property Task
    )

    $Data = @(
        [PSCustomObject]@{ Id = 'Test'; Note = "Test"; Task = "Test" }
        [PSCustomObject]@{ Id = 'Test1'; Note = $null; Task = "Test" }
        [PSCustomObject]@{ Id = 'Test2'; Note = $null; Task = "Test" }
        [PSCustomObject]@{ Id = 'Test3'; Note = $null; Task = "Test" }
        [PSCustomObject]@{ Id = 'Test4'; Note = $null; Task = "Test" }
    )

    New-UDTable -Id 'errors' -Data $Data -Columns $ErrorsGridColumns -Title 'Latest Errors' -ShowPagination -Dense

This issue can be tracked here: Cannot read property version of null in New-UDTable · Issue #149 · ironmansoftware/issues · GitHub

Wow!! You are some sort of sorcerer!! :smiley:

Many thanks!!

Side question unrelated to this, is there a way to bold the column names? I can do another post if needed.

I specialize in magic :stuck_out_tongue:

I think the only way to do that right now is to do some custom CSS with New-UDStyle.

I have a post about that here: Universal Dashboard v3 Themes and Styles

1 Like

For some reason New-UDStyle cmdlet is not getting loaded into the dashboard

[04-29-21 12:22:58 PM] Loading command: New-UDSelect 
[04-29-21 12:22:58 PM] Loading command: New-UDSelectGroup 
[04-29-21 12:22:58 PM] Loading command: New-UDSelectOption 
[04-29-21 12:22:58 PM] Loading command: New-UDSkeleton 
[04-29-21 12:22:58 PM] Loading command: New-UDSlider 
[04-29-21 12:22:58 PM] Loading command: New-UDSpan 
[04-29-21 12:22:58 PM] Loading command: New-UDSparkline 
[04-29-21 12:22:58 PM] Loading command: New-UDSplitPane 
[04-29-21 12:22:58 PM] Loading command: New-UDStep 
[04-29-21 12:22:58 PM] Loading command: New-UDStepper 
[04-29-21 12:22:58 PM] Loading command: New-UDSwitch 
[04-29-21 12:22:58 PM] Loading command: New-UDTab 
[04-29-21 12:22:58 PM] Loading command: New-UDTable 
[04-29-21 12:22:58 PM] Loading command: New-UDTableColumn 
[04-29-21 12:22:58 PM] Loading command: New-UDTableTextOption 
[04-29-21 12:22:58 PM] Loading command: New-UDTabs 
[04-29-21 12:22:58 PM] Loading command: New-UDTextbox 
[04-29-21 12:22:58 PM] Loading command: New-UDTheme 
[04-29-21 12:22:58 PM] Loading command: New-UDTimePicker 
[04-29-21 12:22:58 PM] Loading command: New-UDTooltip 
[04-29-21 12:22:58 PM] Loading command: New-UDTransition 
[04-29-21 12:22:58 PM] Loading command: New-UDTreeNode 
[04-29-21 12:22:58 PM] Loading command: New-UDTreeView 
[04-29-21 12:22:58 PM] Loading command: New-UDTypography 

Make sure to add the component library to your dashboard. On the dashboard page, click components and then add the style component.

Yep. That was it :frowning: Completely forgot about that part.

Thanks for all your help!