Server Side Processing Grid

@adamdriscoll tweeted this past week about how he was working with someone and found a large number of endpoints being created. I have seen the same issue where I have ended up with a high number of endpoints as I was creating some buttons and putting this into my cache. Doing so meant I ended up with a lot of endpoints (as I had three buttons and 12k records).

Adam’s recommendation was to create the buttons as I built the grid and to use server-side processing. In theory, I believe this means I shouldn’t create an endpoint for each record in the grid, but it seems like I still am generating a large number of endpoints. What might I be doing wrong in this?

New-UDGrid -Title “Users” -Headers @(“Enabled”, “Display Name”, “Company”, “Department”, “Primary Role”, “H”, “R”, “I”) -Properties @(“EnabledStatus”, “DisplayNameLink”, “Company”, “Department”, “PrimaryRoleGroup”, “H”, “R”, “I”) -PageSize 150 -Id “UserGridPSS” -Endpoint {
#Overrides filtering, sorting and paging. This ensures that SQL does the actions.
#All UDGrid endpioints have the following variables:
# - $sortAscending - Whether or not the sort is ascending
# - $sortColumn - The name of the column to sort on
# - $filterText - The text to filter the data by
# - $skip - The number of items to skip (used in paging)
# - $take - The number of items to return (used in paging)

$SortColumn = "DisplayName"
$UserGridWithFilter = $cache:UserList | Sort-Object Name | Where-Object {
	$_.DisplayName -like "*$filterText*"
} #| Sort-Object -Property $sortColumn |
#Select-Object -First $take -Skip $skip |
#Out-UDGridData

$UserGridWithFilterCount = $UserGridwithFilter.count

#$UserGridWithFilter
$UserGridwithFilter | ForEach-Object {
	$DisplayName = $_.DisplayName
	$ADSAM = $_.samaccountname
	$Enabled = $_.Enabled
	$FullDisplayName = $_.idFullDisplayName
	$ADThumbNailPhoto = $_.thumbnailphoto
	
	If ($ADThumbNailPhoto) {
		$ThumbnailPhoto = [convert]::ToBase64String($ADThumbNailPhoto)
	} Else {
		$ThumbnailPhoto = $NoThumbnailPhoto
	}
	
	
	$EnabledStatus = New-UDIcon -Icon check_circle -Size 2x -Color green
	$DisplayNameLink = New-UDTooltip -TooltipContent { "Full User View" } -Content {
		New-UDHtml -Markup "<a href=""/Users/$ADSAM"" >$DisplayName</a>" #target=""_blank""
	}
	
	
	$UserButton = New-UDTooltip -TooltipContent { "User Quick View" } -Content {
		New-UDButton -Icon info_circle -OnClick {
			Show-UDModal -Header {
				New-UDHtml -Markup "<img style=""float: left; border-radius: 75%; max-width: 100%;

height: auto;"" src="“data:image/jpeg; base64,$ThumbnailPhoto”" alt="“User Thumbnail Photo”">"
New-UDMuTypography -Variant h5 -Text “FullDisplayName" New-UDMuTypography -Variant h6 -Text .title
New-UDMuTypography -Variant subtitle1 -Text _.company New-UDMuTypography -Variant subtitle1 -Text
.department
} -Content {
$UserCache = Cache:UserList | Where-Object { _.displayname -eq $DisplayName }
New-UDTable -Title “$DisplayName Info” -Headers @(” ", " ") -Content {

					$UserEmployeeType = $UserCache.EmployeeType
					$UserEmployeeNumber = $UserCache.EmployeeNumber
					$UserEmail = $UserCache.mail
					
					@{
						"Employee Type"    = $UserEmployeeType
						"Employee Number"  = $UserEmployeeNumber
						"Email Address"    = $UserEmail
					}.GetEnumerator() | Out-UDTableData -Property @("Name", "Value")
				} -ArgumentList $UserName
				
				
				New-UDTable -Id "PasswordInfo" -Title "Password and Account Info" -Headers @(" ", " ") -Content {
					
					
					$tablePwd = [ordered]@{
						'Password Expiration' = $UserCache.idPasswordExpiration
						'Account Expiration'  = $UserCache.idAccountExpiration
						'Last Logon Timestamp' = $UserCache.idLastLogon
					}
					$TablePwd.GetEnumerator() | Out-UDTableData -Property @("Name", "Value")
				}
				
			} #END Modal
			
		} #END UserButton
	} #END User Tooltip
	$ResetPassword = New-UDTooltip -TooltipContent { "Reset Password, Unlock Account, Extend Expiration" } -Content {
		New-UDButton -Icon unlock -OnClick {
			#key_skeleton, unlock, lock_open
			Invoke-UDRedirect -Url "/UserResetPwd/$ADSAM" #-OpenInNewWindow
		}
	}
	$RoleAssign = New-UDTooltip -TooltipContent { "Basic User Quick Task" } -Content {
		New-UDButton -Icon user_cog -OnClick {
			#key_skeleton, unlock, lock_open
			Invoke-UDRedirect -Url "/UserRole/$ADSAM" #-OpenInNewWindow
		}
	}
	
	$PSObject = [PSCustomObject]@{
		EnabledStatus   = $EnabledStatus
		DisplayNameLink = $DisplayNameLink
		Company		    = $_.Company
		Department	    = $_.Department
		PrimaryRole	    = $_.tsaPrimaryRoleGroup
		H			    = $RoleAssign
		R			    = $ResetPassword
		I			    = $UserButton
		
	}

	$PSObject
} | Sort-Object -Property $sortColumn |
Select-Object -First $take -Skip $skip |
Out-UDGridData -TotalItems $UserGridWithFilterCount

} -ServerSideProcessing