Here’s a weird one… I’m building out a report for battery health of our laptops. I had the thought to have it display a graph of the battery health in the last 30 days, but when the row is expanded, the chart is…
- Bigger than the table
- expands infinitely vertically and horizontally…
Any thoughts?
$BQuery = @"
SQLQuery here
"@
$BatteryAll = Invoke-DbaQuery -SqlInstance $Instance -Database $Database -query $BQuery -As PSObject
$IDs = $BatteryAll | Select-Object -ExpandProperty snid -Unique
$BatteryReport = $IDs | ForEach-Object -Parallel {
$ID = $_
$Batteryall = $Using:Batteryall
$BatteryAll | Where-Object {$_.Snid -eq $ID} | Sort-Object Timestamp -Descending | Select -First 1
}
$Columns = @(
New-UDTableColumn -Property DeviceName -Title "Device Name" -Render {
New-UDLink -Text $EventData.'snid' -url "ComputerManagement/$($EventData.snid)" -OpenInNewWindow
} -FilterType text -ShowFilter
New-UDTableColumn -Property Model -FilterType AutoComplete -ShowFilter
New-UDTableColumn -Property DesignCapacity -Title "Design Capacity (mAh)"
New-UDTableColumn -Property CurrentCapacity -Title "Current Capacity (mAh)"
New-UDTableColumn -Property Percentage -Render {
Switch ($EventData.Percentage) {
{$_ -le 50} {
New-UDAlert -Severity 'error' -Text "$_%";Break
}
{$_ -le 75} {
New-UDAlert -Severity 'warning' -Text "$_%";break
}
{$_ -le 100} {
New-UDAlert -Severity 'success' -Text "$_%";break
}
}
} -FilterType Range -ShowFilter
New-UDTableColumn -Property TimeStamp -Render {
New-UDDateTime -InputObject $EventData.TimeStamp
}
)
New-UDTable -Title "Battery Report" -Columns $Columns -Data $BatteryReport -PageSize 10 -ShowPagination -ShowFilter -OnRowExpand {
$Data = $BatteryAll | Where-object {$_.snid -eq $EventData.snid} | Select-Object -First 30
$Baseline = New-UDChartJSDataset -DataProperty DesignCapacity -Label "Design Capacity (mAh)"
$Actual = New-UDChartJSDataset -DataProperty CurrentCapacity -Label "Current Capacity (mAh)"
$Options = @{
type = 'line'
Data = $Data
Dataset = @($Baseline,$Actual)
LabelProperty = "TimeStamp"
}
New-UDChartJS @Options
}