New-UDTable: server side filtering auto resets

Hi, I’m using New-UDTable and I’m trying to use both -LoadData and -ShowFilter on the column, I can see that it works, but only for a split second, after that it auto resets and removes the inserted text from the filter. It feels to me that it’s trying to use both clientside and serverside filtering at the same time. One observation for example is that it does work once the total results are smaller than the pagesize set. In my case though, I’m working with 10000+ records and that just doesn’t perform when sending all that data to the client in one go.

I tested these scenario’s, with both Edge (chromium based one) and Chrome:

  1. Use a dataset of 10000 items, pagesize of 25, filters don’t work.
  2. Use a dataset of 50 items, pagesize of 25, filters don’t work.
  3. Use a dataset of 25 items, pagesize of 25, filters work correctly in this scenario!

Edit, one more noteworthy item, the filter always shows “search 26 records”, while the total number of results is higher and is correctly passed (I do see the correct value in the bottom of the table, so -TotalCount is getting the right value, but it’s not processed correctly in the filter it seems.

Here is the code I used:

New-UDTable -LoadData {
        $tableData = ConvertFrom-Json -InputObject $Body
        $sessions = Get-PSUCache -Key allsessions

        if ($tableData.Filters) {
            $whereFilters = foreach ($filter in $tableData.Filters) {
                '$_.{0} -like "*{1}*"' -f $filter.id, $filter.value
            }

            $whereScriptBlock = [scriptblock]::Create($whereFilters -join ' -and ')
            $sessionOutput = $sessions | Where-Object -FilterScript $whereScriptBlock
        } else {
            $sessionOutput = $sessions
        }

        $start = $tableData.page * $tableData.PageSize
        $end = $start + $tableData.pageSize
        
        $sessionOutput[$start..$end] | Out-UDTableData -Page $tableData.page -TotalCount $sessionOutput.Count -Properties $tableData.properties
    } -PageSize 25 -PageSizeOptions @(25,100,500,1000) -ShowPagination -Dense -Columns @(
        New-UDTableColumn -Property IpAddress -Title 'IP Address' -ShowFilter -FilterType text
    )
}
Product: PowerShell Universal / Universal Dashboard
Version: 1.5.8 / 3.2.5

server-side processing depends on you to do the filtering, totalCount on server-side processing is only used for calc the number of pages the pagination will have, but that only for the UI view, it does not actually populate all the pages the pagination show you when doing server-side processing the table will query the server for the current page, and it expects to get only the amount of data that the PageSize is,

if you wanna send all your data in one go to the table don’t use server-side, if you send all you data in one go to the table, the table will handle all the filtering and pagination for you.

take a look at this Build Server-Side tables with PowerShell Universal Dashboard (ironmansoftware.com)

I did look at the blog post before I posted this issue, the problem here is that it doesn’t work as expected. I think the way the filter is implemented in the code I pasted above, should be all that is needed to implement the server-side processing?

The problem is that, after implementing this, I can see that the results are returned, but right after that (within the same second) the search is reset (so the text disappears from the filter). This feels like a bug in UD.

can you post me some sample data to work with?
do you use the global filter or column custom filter,
if you can screen record this it will be appreciated

Here is a full repo of the issue, I also noticed it actually does not happen when typing very slowly, I’ve also attached a video to show the behavior.

Code used:

$page = New-UDPage -Name 'Filter' -Content {
    New-UDTable -LoadData {
        $tableData = ConvertFrom-Json -InputObject $Body
        $sessions = 16777226..16778000 | Foreach-Object {
            $ip = [ipaddress]$_
            [pscustomobject]@{
                IPAddress = $ip.IPAddressToString
            }
        }

        if ($tableData.Filters) {
            $whereFilters = foreach ($filter in $tableData.Filters) {
                '$_.{0} -like "*{1}*"' -f $filter.id, $filter.value
            }

            $whereScriptBlock = [scriptblock]::Create($whereFilters -join ' -and ')
            $sessionOutput = $sessions | Where-Object -FilterScript $whereScriptBlock
        } else {
            $sessionOutput = $sessions
        }

        $sessionOutputToHashTable = $sessionOutput | Foreach-Object {
            @{
                IPAddress = $_.IPAddress
            }
        }

        $start = $tableData.page * $tableData.PageSize
        $end = $start + $tableData.pageSize

        $sessionOutputToHashTable[$start..$end] | Out-UDTableData -Page $tableData.page -TotalCount $sessionOutput.Count -Properties $tableData.properties
    } -PageSize 5 -PageSizeOptions @(5,25) -ShowPagination -Dense -Columns @(
        New-UDTableColumn -Property IPAddress -Title 'IP Address' -ShowFilter -FilterType text
    )
}

New-UDDashboard -Pages $page

How it behaves: https://youtu.be/WcI-aK-QHJ4 (as can be seen in the video, I try to filter on something that start with 10., that only starts to work once I type it very slowly, please note I’m not pressing backspace myself here (or deleting the inserted text in another way), the text in the filter is removed by UD.

Thanks for all the info i will take a look at this

Thanks @AlonGvili, this one is quite a blocker for the (proper) use of UD for my use case, I hope it can be resolved quickly. Am I correct in assuming this is a bug in UD?

Probably a bug, i will take a look at this tonight.

Any luck squashing that bug @AlonGvili?

close to, I’m currently testing my changes

That looks a lot better, thanks @AlonGvili. Expected in PSU 1.5.9?

:man_shrugging:

If you don’t know, who does? @adam maybe?

Yeah. We should be able to get this in 1.5.9