I may be wrong, but looking at your code I think you’re missing the point in the server side rendering. The idea is that the table data is paginated and therfore only makes the necessary call to get only that page of data from your source system, when a user clicks to view the next page, an additional call is made at that point, vastly reducing the overhead, because you’re only pulling x records at a time.
If you’re creating server side processing tables for the purpose of optimizing the responsiveness you should never pull all the data in one go.
Am i right in thinking that you are doing this in your $ExtendProviderList variable in the second line of your code?
If so you will need to make some adjustments to ensure that the call to obtain the data is within the -LoadData script block, and you are utilizing pagination in those calls.
Also the article you have referenced is a very old version of powershell universal - it’s not relevant to the version you’re using, it might be best to refer to documentation here instead: Table | PowerShell Universal
In general, you are using the right approach: you need to use the -LoadData parameter and add a scriptblock to add where you specify how your data is loaded with filtering, pageination …
Note:
What I had to understand at the beginning is the fact that with LoadData you have to do the filtering, pagination, sorting etc. yourself in the LoadData script block. So everything that a user specifies/does in the table in the browser (entering filters, sorting a column, etc.) must be done in LoadData itself. If you enter a filter in a column, you have to calculate how many values match this filter and adjust the Pages and TotalSize etc. accordingly. If a user clicks on a column to sort it, you have to recognize this and sort your PowerShell object yourself.
The most important thing is that you pass a PowerShell object with, for example, 50000 data records. With the pagination that you calculate yourself, however, only e.g. 15 entries (PageSize) are obtained from the object and displayed. Therefore the initial loading is much faster, but it could take a little longer when changing pages.
Here is an example from one of our custom functions:
The code creates a hashtable with all parameters later used with splatting for New-UDTable.
$InputData or $Data contains your data for the table to show (in this example).
# Example $Data
$Data = [System.Collections.ArrayList]::new()
$Data = $InputData | ForEach-Object {
[PSCustomObject]@{
'Column1' = [float]$_.column1
'Column2' = [string]$_.column2
'Column3' = [Int]$_.column3
'Column4' = [Int]$_.column4
'Column5' = [string]$_.column5
'Column6' = [Int]$_.column6
'Column7' = [Int]$_.column7
}
}
#region New-UDTable parameter
$params_table = @{
Id = "table_$($UniqueId)_table_data"
Columns = $objColumns
PaginationLocation = $PaginationLocation
PageSize = $PageSize
ShowPagination = $ShowPagination
ShowFilter = $ShowFilter
ShowSearch = $ShowSearch
ShowExport = $ShowExport
ShowSort = $true
DefaultSortDirection = $DefaultSortDirection
TextOption = $Options
}
if ($Dense) {
$params_table['Dense'] = $true
}
$params_table['LoadData'] = {
# if something was added to the filter on top of the columns, filter the data
foreach ($Filter in $EventData.Filters) {
$Data = $Data | Where-Object -Property $Filter.Id -Match -Value $Filter.Value
}
# Get TotalCount of the input data to calculate pagination
$TotalCount = $Data.Count
# if one table column will be sorted (someone clicked on the sorting in the table, sort also the content
if (-not [string]::IsNullOrEmpty($EventData.OrderBy.Field)) {
$Descending = $EventData.OrderDirection -ne 'asc'
$Data = $Data | Sort-Object -Property ($EventData.orderBy.Field) -Descending:$Descending
}
# calculate page amount, each page size (default 5) based on the total objects
$Data = $Data | Select-Object -First $EventData.PageSize -Skip ($EventData.Page * $EventData.PageSize)
# output the data to the table
$Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties
}
#endregion
New-UDTable @params_table