Hi,
When using -LoadData for UDTable the Search box won’t work.
Wondering if I’m doing something wrong or is search broken?
$SearchText = New-UDTableTextOption -Search "$tl:Search"
New-UDTable -Id "tableGroupMembership" -Columns $Columns -LoadData {
$TotalCount = $Data.Count
if (-not [string]::IsNullOrEmpty($EventData.OrderBy)) {
$Descending = if ($EventData.OrderDirection -ne 'asc') { $false } else { $true }
if ($Descending -eq $true) {
$Data = $Data | Sort-Object -Property "$($EventData.orderBy | Out-String)" -Descending
}
else {
$Data = $Data | Sort-Object -Property "$($EventData.orderBy | Out-String)"
}
}
$Data = $Data | Select-Object -First $EventData.PageSize -Skip ($EventData.Page * $EventData.PageSize)
$Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties
} -PaginationLocation top -TextOption $SearchText -ShowSearch -ShowPagination -Dense -PageSize 8 -ShowSort -RemoveCard -DisableSortRemove -Size small -DefaultSortDirection ascending
I have opened a GitHub issue for it also table when using -LoadData search box won't work. · Issue #2723 · ironmansoftware/issues · GitHub
I have been looking at the -LoadData parameter on tables and you have to do all the work on the data yourself. You would need to get the $EventData.search field in the -LoadData ScriptBLock , that includes what the user has typed into the search box, and use that to filter $Data. Every time I find that I am unable to get LoadData to work as I wanted and go back to using -Data $Data.
This is how I filter data when using LoadData. Sorry for the ugly lack of a codeblock, I’m on mobile right now.
foreach ($Filter in $EventData.Filters) {
$Data = $Data | Where-Object -Property $Filter.ID -Match -Value $Filter.Value
}
if (-not [string]::IsNullOrEmpty($EventData.OrderBy.Field)) {
$Descending = $EventData.OrderDirection -ne ‘asc’
$Data = $Data | Sort-Object -Property ($EventData.orderBy.Field) -Descending:$Descending
} else {
$Data = $Data | Sort-Object -Property ‘Name’
}
$TotalCount = $Data.Count
$Data = $Data | Select-Object -First $EventData.PageSize -Skip ($EventData.Page * $EventData.PageSize)
$Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties