Dashboard tables: I have followed instructions and blog articles https://blog.ironmansoftware.com/universal-dashboard-server-side-table/ & https://docs.ironmansoftware.com/dashboard/components/data-display/table to create a table.
I am using Universal Powershell 1.3.1, Powershell 7 and V3 Dashboard.
The code gets ad group members and displays them in a server-side table, however when creating a button within the table, the first page works great but when I go to the next page the button refers to the values of the first page.
For troubleshooting purposes, I have named the button after the user login.
It will be me! But could anyone advise me on where I have gone wrong? If I select 20 rows on a page then it will work only when I move away from page one does it fail!
Code:
New-UDDynamic -Id 'results' -Content {
New-UDTable -Title "Members" -LoadData {
$TableGroupData = ConvertFrom-Json $Body
<# $Body will contain
filters: []
orderBy: undefined
orderDirection: ""
page: 0
pageSize: 5
properties: (6) ["Name", "Samaccountname", "Title", "Department", "Telephone", "Action" ]
search: ""
totalCount: 0
#>
# Calculate the number of rows to skip - fixes paging issue
$PageSize = $TableGroupData.PageSize
$Offset = $TableGroupData.Page * $PageSize
$Nxtrow = $offset + 5
$count = (Get-ADGroupMember $session:PassGroupName).count
$Session:Groupdisplay = (Get-ADGroupMember $session:PassGroupName -Credential $Cache:DomainCred | get-aduser -Credential $Cache:DomainCred -Properties Displayname, title, Company, Department, telephoneNumber | Select Displayname, title, department, telephoneNumber, SamAccountName)[$Offset..$Nxtrow]| ForEach-Object {
@{DisplayName = $_.DisplayName
Samaccountname = $_.samaccountname
Title = $_.Title
Department = $_.Department
telephoneNumber = $_.telephoneNumber
}
}
$Session:Groupdisplay | Out-UDTableData -TotalCount $count -Page $TableGroupData.page -Properties $TableGroupData.properties } -Columns @(
New-UDTableColumn -Property Displayname -Title "Name"
New-UDTableColumn -Property Samaccountname -Title "User ID"
New-UDTableColumn -Property Title -Title "Title"
New-UDTableColumn -Property Department -Title "Department"
New-UDTableColumn -Property telephoneNumber -Title "Telephone"
New-UDTableColumn -Property Action -Title "Action" -Render {
$Item = $Body | ConvertFrom-Json
New-UDButton -Id "btn$($Item.Displayname)" -Text "$($Item.samaccountname)" -OnClick {
Show-UDToast -Message "Removing user $($Item.displayname)" -Duration 5000
Remove-ADGroupMember -Credential $Cache:DomainCred -Identity $session:PassGroupName -Members $Item.Samaccountname -Confirm:$false -ErrorAction SilentlyContinue
Sync-UDElement -iD 'results'
}
}
)
}