Result of New-UDInput to be output in new-UDTable or New UDGrid below

I have this sample code here

New-UDPage -Name "OpenFiles"  -Content {
New-UDInput -Title "Enter Partial file name" -Endpoint {
    param(
        [string]$phrase
    )

    $a = Get-ChildItem -Path C:\Temp

    $FilesFound = $a |Where-Object -Property fullname -Like "*$phrase*" -erroraction stop 




New-UDInputAction -Content {
                    #Show-Toast to show that some data was returned
                    foreach ($item in $FilesFound )
                    {Show-UDToast -Message $item.FullName -duration 600000
                    }
                    # New-UDGrid -Title "File Information"  -Endpoint {
                    #     $Result  | Out-UDGridData
                    # }

                    New-UDTable  -Title "Files" -Header @("name", "FullName ") -Endpoint {
                        $FilesFound  | Out-UDTableData -Property @("name", "FullName")
                    }
     }#close input action
}

}

At the moment the New-UDInputAction does as it is supposed to do and replace the input dialog with the results
What I want to have happen is that input dialog stays and the results are outputted to a grid or table below.
Is that do-able?

In that case, ditch your New-UDInputAction -Content since this is specifically to replace the content of the form by the output from the content scriptblock.

Instead, you could create an empty named div through New-UDElement that would create the UDTable based on the results of the form, which you need to store in a $Session or $Cache variable.

Based on whether or not files were found, the Table / grid might be created.
The magic cmdlet is Sync-UDElement in your UDInput endpoint to trigger a refresh of your UDElement.

See the sample below.
(I used $Cache in my example rather than $Session due to the latter being broken currently but in a multi-user scenario, you would want to store the results in a session variable instead)

New-UDPage -Name "OpenFiles"  -Content {
    New-UDInput -Title "Enter Partial file name" -Endpoint {
        param(
            [string]$phrase
        )

        $a = Get-ChildItem -Path "C:\Temp"

        $Cache:FilesFound = $a | Where-Object -Property fullname -Like "*$phrase*" -erroraction stop 
            Sync-UDElement -Id 'results'

    }

    New-UDElement -Id 'results' -Tag 'div' -Endpoint {
        if ($Cache:FilesFound -ne $null) {
            New-UDTable -Id 'results'  -Title "Files" -Header @("name", "FullName ") -Endpoint {
                $Cache:FilesFound | Out-UDTableData -Property @("name", "FullName")
            }    
        }
    
    }
}

3 Likes

That is just awesome. Thanks!
Any chance of getting it to work with New-UDGrid ?

All i get is a sparkline continually moving from left to right and no results

In the marketplace (https://marketplace.universaldashboard.io/) there’s an ‘Active Directory’ Dashboard, one of the pages is called ‘Search’ which takes input, and puts it to a grid.

Maybe you can salvage the code from there?

Do you guys knows if there is a limitation of “New-UDElement” you can add to a page ? I tried to the the exact same as @itfranck but with 2 UDElements that I want to show up one after the other. As soon as I click on the UDInput, the dashboard simply crashed, If I remove the second UDElement it works back again. What I’m trying to achieve is having a two Inputs that lead to a chart and the first will drive second’s UDInput’s content and both UDInput content will be used to construct the chart. Have you ever experience this kind of behavior ?

Edit: I nested the Second New-UDElement in the first one, then did a @(“Elem1”,“Elem2”) | Sync-UDElement and it worked out.