Data Grid
Data grid component for Universal Dashboard.
Last updated
Data grid component for Universal Dashboard.
Last updated
Copyright 2024 Ironman Software
The UDDataGrid
component is an advanced version of the table that is useful for displaying large amounts of data. It supports many of the same features as the table but also provides complex filtering, row virtualization, multi-column sort and more.
Data grids load their data via the -LoadRows
event handler. You will need to return a hashtable that contains the row data and the total number of rows.
Columns are defined using hashtables.
Prior to version 3.3., column field names must be in camel case. For example, the property Name
would need to be name
while the property FirstName
would need to be firstName
.
Columns are customizable using hashtables. You can find the supported properties below.
You can render custom components in columns by specifying render
within the column hashtable. You can access the current row's data by using the $EventData
or $Row
variable
In this example, the number is shown in the name column with a New-UDTypography
component.
Column fluidity or responsiveness can be achieved by setting the flex
property of a column.
The flex
property accepts a value between 0 and ∞. It works by dividing the remaining space in the grid among all flex columns in proportion to their flex
value.
For example, consider a grid with a total width of 500px that has three columns: the first with width: 200
; the second with flex: 1
; and the third with flex: 0.5
. The first column will be 200px wide, leaving 300px remaining. The column with flex: 1
is twice the size of flex: 0.5
, which means that final sizes will be: 200px, 200px, 100px.
To set a minimum and maximum width for a flex
column set the minWidth
and the maxWidth
property on the column.
The -LoadRows
parameter is used to return data for the data grid. Table state will be provided to the event handler as $EventData
. You will find the following properties within the $EventData
object.
To implement paging, you can access the page
and pageSize
properties of the $EventData
variable.
The filter hashtable is included in the $EventData
for the -LoadRows
event handler when a filter is defined. The hashtable has a structure as follows.
The items property contains an array of columns, operators and values. You can use these to filter your data.
The link operator field is used to specify the link between the filters. This can be and
or or
.
The $EventData
object will contain a Sort
property when the user sorts the data grid. It contains properties for each column that is sorted. The properties will start as 0 and increment as more columns are sorted.
For example, you can access the first sorted column as follows.
You will also receive the sort direction for each column.
You can use the -LoadDetailedContent
event handler to display additional information about the row you are expanding. Information about the current row is available in $EventData.row
.
Tables provide editor support by specifying the -OnEdit
event handler. The new row data will be provided as $EventData
. You can chose to return updated row information (for example, adjusting something the user has entered) and return it from the event handler. If you do not return anything, the row will reflect what the user entered.
The $EventData
has the following format.
Ensure that you provide the editable
property to each column you wish for the user to edit.
To override the default export functionality, use the -OnExport
event handler. $EventData
will be an array of rows with their values. You should use Out-UDDataGridExport
to return the data from -OnExport
.
In this example, we generate an array of 10,000 records. We will create a new function, Out-UDDataGridData
to manage the paging, sorting and filtering.
In this example, we'll query the PowerShell Universal database with dbatools.
Property | Description | Type\Value |
---|---|---|
Property | Description | Type |
---|---|---|
Property | Description | Type |
---|---|---|
Property | Description | Type |
---|---|---|
Align
How to align the data within the column.
Left, Center, Right
CellClassName
A CSS class to apply to cells in this column
string
ColSpan
The number of columns this column should span.
Integer
Description
A tooltip description of the column
string
DisableColumnMenu
Disable the column menu for this column
boolean
DisableExport
Disable exporting of the data in this column
boolean
Editable
Whether or not this column can be edited
boolean
Field
The field (property) to use when displaying the value in the column.
String
Filterable
Whether this column can be used in filters.
boolean
Flex
The flex
property accepts a value between 0 and ∞. It works by dividing the remaining space in the grid among all flex columns in proportion to their flex
value.
float
HeaderAlign
How to align header text.
left, center, right
HeaderName
The title to display in the header.
String
Hide
Whether to hide the column
boolean
Hideable
Whether a column can be hidden by the user.
boolean
HideSortIcon
Whether to hide the sort icon for the column
boolean
MaxWidth
The maximum width of the column
integer
MinWidth
The minimum width of the column
integer
Pinnable
Whether the column can be pinned.
boolean
Render
A script block to render components in the column
ScriptBlock
Resizable
Whether the column can be resized
boolean
Sortable
Whether the column can be sorted.
boolean
Type
The type of data within the column
string, number, date, dateTime, boolean, actions
Width
How wide the column should be in pixels.
Integer
Filter
A filter object that you can use to construct filters against your data.
Hashtable
Page
The current page. Starts at 0.
Integer
PageSize
The number of records in a page.
Integer
Sort
The sort options for the table
Hashtable
ColumnField
The name of the field to filter
String
OperatorValue
The type of operator to use when filtering the data.
String
Value
The value used to filter
Object
Field
The field to sort.
String
Sort
The direction to sort the field.
asc, desc