> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/powershell-commands/new-udtable.md).

# New-UDTable

New-UDTable builds a data table in PowerShell Universal with sorting, filtering, searching, paging, and server-side data loading support.

### Synopsis

Creates a table.

### Syntax

```powershell
New-UDTable [-Id <String>] [-Title <String>] [-Data <Object[]>] [-Columns <Hashtable[]>] [-OnRowSelection <Endpoint>] [-ShowSort] [-ShowFilter] [-ShowSearch] [-Dense] [-ShowExport] [-StickyHeader] [-PageSize <Int32>] [-PageSizeOptions <Int32[]>] [-PaginationLocation <String>] [-ShowSelection] [-ShowPagination] [-Padding <String>] [-Size <String>] [-TextOption <Hashtable>] [-ExportOption <String[]>] [-OnExport <Endpoint>] [-DisablePageSizeAll] [-DefaultSortDirection <String>] [-HideToggleAllRowsSelected] [-DisableMultiSelect] [-DisableSortRemove] [-Icon <Hashtable>] [-ClassName <String>] [-ShowRefresh] [-ToolbarContent <ScriptBlock>] [-OnRowExpand <ScriptBlock>] [-MaxHeight <Int32>] [-Language <String>] [-RemoveCard] [-OnRowStyle <ScriptBlock>] [-HeaderStyle <Hashtable>] [-InitialState <Hashtable>] [<CommonParameters>]

New-UDTable [-Id <String>] [-Title <String>] -LoadRows <Endpoint> [-Columns <Hashtable[]>] [-OnRowSelection <Endpoint>] [-ShowSort] [-ShowFilter] [-ShowSearch] [-Dense] [-ShowExport] [-StickyHeader] [-PageSize <Int32>] [-PageSizeOptions <Int32[]>] [-PaginationLocation <String>] [-ShowSelection] [-ShowPagination] [-Padding <String>] [-Size <String>] [-TextOption <Hashtable>] [-ExportOption <String[]>] [-OnExport <Endpoint>] [-DisablePageSizeAll] [-DefaultSortDirection <String>] [-HideToggleAllRowsSelected] [-DisableMultiSelect] [-DisableSortRemove] [-Icon <Hashtable>] [-ClassName <String>] [-ShowRefresh] [-ToolbarContent <ScriptBlock>] [-OnRowExpand <ScriptBlock>] [-MaxHeight <Int32>] [-AutoRefresh] [-AutoRefreshInterval <Int32>] [-Language <String>] [-RemoveCard] [-OnRowStyle <ScriptBlock>] [-HeaderStyle <Hashtable>] [-InitialState <Hashtable>] [<CommonParameters>]
```

### Description

Creates a table. Tables are used to show both static and dynamic data. You can define columns and data to show within the table. The columns can be used to render custom components based on row data. You can also enable paging, filtering, sorting and even server-side processing.

### Parameters

#### -Id

The ID of the component. It defaults to a random GUID.

```
Required?                    false
Position?                    named
Default value                [Guid]::NewGuid().ToString()
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Title

The title to show at the top of the table's card.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Data \<Object\[]>

The data to put into the table.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -LoadRows

When using dynamic tables, this script block is called. The $Body parameter will contain a hashtable the following options:

filters: @() orderBy: string orderDirection: string page: int pageSize: int properties: @() search: string totalCount: int

You can use these values to perform server-side processing, like SQL queries, to improve the performance of large grids.

After processing the data with these values, output the data via Out-UDTableData.

```
Required?                    true
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Columns \<Hashtable\[]>

Defines the columns to show within the table. Use New-UDTableColumn to define these columns. If this parameter isn't specified, the properties of the data that you pass in will become the columns.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnRowSelection

A script block to call when a row is selected. $EventData will contain the selected rows.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowSort

Whether to show sort controls on columns

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowFilter

Whether to show filter controls on columns

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowSearch

Whether to show full table search

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Dense

Reduces the white-space used within the table.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowExport

Whether to show the export button.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -StickyHeader

Makes the header sticky.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -PageSize

The default page size.

```
Required?                    false
Position?                    named
Default value                5
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -PageSizeOptions \<Int32\[]>

An array of available page size options.

```
Required?                    false
Position?                    named
Default value                @()
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -PaginationLocation

Where to show the pagination controls. Valid values are top, bottom, or both. Defaults to bottom.

```
Required?                    false
Position?                    named
Default value                bottom
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowSelection

Whether to allow selection within the table.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowPagination

Whether to show pagination controls.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Padding

```
Required?                    false
Position?                    named
Default value                default
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Size

The size of the table. Defaults to medium. Valid values are medium and small.

```
Required?                    false
Position?                    named
Default value                medium
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -TextOption

Customizations to standard text within the table. Use New-UDTextOption to create the text options.

```
Required?                    false
Position?                    named
Default value                (New-UDTableTextOption)
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ExportOption \<String\[]>

An array of export options.

```
Required?                    false
Position?                    named
Default value                @("XLSX", "PDF", "JSON", "CSV")
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnExport

A script block used to customize how the export is performed.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -DisablePageSizeAll

Removes the All option from page size options.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -DefaultSortDirection

The default sort direction.

```
Required?                    false
Position?                    named
Default value                ascending
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -HideToggleAllRowsSelected

Hides the toggle all rows selected button.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -DisableMultiSelect

Disables multi-select.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -DisableSortRemove

Removes the sort option for unsorted columns. Columns will always be ascending or descending.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Icon

Sets an icon next to the title. Use New-UDIcon to create the icon.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ClassName

A CSS class to apply to the table.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowRefresh

Whether to show the refresh button.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ToolbarContent

Custom content to show in the toolbar.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnRowExpand

A script block to call when a row is expanded. The $EventData variable will contain the row data.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -MaxHeight

```
Required?                    false
Position?                    named
Default value                0
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -AutoRefresh

Reloads the table on an interval when -LoadRows is being used.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -AutoRefreshInterval

The interval to reload data when AutoRefresh is specified.

```
Required?                    false
Position?                    named
Default value                10
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Language

The language. Primarily used for Date and Time filters.

```
Required?                    false
Position?                    named
Default value                en
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -RemoveCard

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnRowStyle

A script block to call to style rows. The $EventData variable will contain the row data.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -HeaderStyle

A hashtable of styles to apply to the header.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -InitialState

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### Common parameters

This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see [about\_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

### Outputs

### Examples

#### Example 1: Basic Table

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)
New-UDTable -Data $Data -Id 'table1'
```

Creates a static table whether the columns of the table are the properties of the data specified.

#### Example 2: Columns

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)
$Columns = @(
    New-UDTableColumn -Property Dessert -Title "A Dessert"
    New-UDTableColumn -Property Calories -Title Calories
    New-UDTableColumn -Property Fat -Title Fat
    New-UDTableColumn -Property Carbs -Title Carbs
    New-UDTableColumn -Property Protein -Title Protein
)
New-UDTable -Data $Data -Columns $Columns -Id 'table2'
```

Creates a table where there are custom columns defined for that table.

#### Example 3: Render

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)
$Columns = @(
    New-UDTableColumn -Property Dessert -Title Dessert -Render {
       New-UDButton -Id "btn$($EventData.Dessert)" -Text "Click for Dessert!" -OnClick { Show-UDToast -Message $EventData.Dessert }
    }
    New-UDTableColumn -Property Calories -Title Calories
    New-UDTableColumn -Property Fat -Title Fat
    New-UDTableColumn -Property Carbs -Title Carbs
    New-UDTableColumn -Property Protein -Title Protein
)
New-UDTable -Data $Data -Columns $Columns -Id 'table3'
```

Creates a table where the columns are rendered with custom content.

#### Example 4: Column Width

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)

$Columns = @(
    New-UDTableColumn -Property Dessert -Title Dessert -Render {
        New-UDButton -Id "btn$($EventData.Dessert)" -Text "Click for Dessert!" -OnClick { Show-UDToast -Message $EventData.Dessert }
    }
    New-UDTableColumn -Property Calories -Title Calories -Width 5 -Truncate
    New-UDTableColumn -Property Fat -Title Fat
    New-UDTableColumn -Property Carbs -Title Carbs
    New-UDTableColumn -Property Protein -Title Protein
)

New-UDTable -Data $Data -Columns $Columns -Id 'table4'
```

Set custom column width

#### Example 5: Column Filter

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)

$Columns = @(
    New-UDTableColumn -Property Dessert -Title "A Dessert" -Filter -FilterType AutoComplete
    New-UDTableColumn -Property Calories -Title Calories -Filter -FilterType Range
    New-UDTableColumn -Property Fat -Title Fat -Filter -FilterType Range
    New-UDTableColumn -Property Carbs -Title Carbs -Filter -FilterType Range
    New-UDTableColumn -Property Protein -Title Protein -Filter -FilterType Range
)

New-UDTable -Id 'table5' -Data $Data -Columns $Columns -ShowFilter
```

Columns filters for a table

#### Example 6: Column Search

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)

$Columns = @(
    New-UDTableColumn -Property Dessert -Title "A Dessert" -IncludeInSearch
    New-UDTableColumn -Property Calories -Title Calories
    New-UDTableColumn -Property Fat -Title Fat
    New-UDTableColumn -Property Carbs -Title Carbs
    New-UDTableColumn -Property Protein -Title Protein
)

New-UDTable -Id 'table6' -Data $Data -Columns $Columns -ShowSearch
```

Columns can be included in the search

#### Example 7

```powershell
$Columns = @(
    New-UDTableColumn -Property Name -Title "Name" -ShowFilter
    New-UDTableColumn -Property Value -Title "Value" -ShowFilter
)

$Data = 1..1000 | ForEach-Object {
[PSCustomObject]@{
    Name = "Record-$_"
    Value = $_
}
}

New-UDTable -Columns $Columns -LoadData {
    foreach($Filter in $EventData.Filters)
    {
        $Data = $Data | Where-Object -Property $Filter.Id -Match -Value $Filter.Value
    }

    $TotalCount = $Data.Count

    if (-not [string]::IsNullOrEmpty($EventData.OrderBy.Field))
    {
        $Descending = $EventData.OrderDirection -ne 'asc'
        $Data = $Data | Sort-Object -Property ($EventData.orderBy.Field) -Descending:$Descending
    }

    $Data = $Data | Select-Object -First $EventData.PageSize -Skip ($EventData.Page * $EventData.PageSize)

    $Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties
} -ShowFilter -ShowSort -ShowPagination -Id 'table7'

Server-Side Processing|Server-side processing is useful for large data sets that should not be loaded into the browser.
```

#### Example 8: Paging

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)

New-UDTable -Data $Data -Paging -PageSize 2 -Id 'table8'
```

Paging can be enabled by setting the -Paging parameter to $true. The default page size is 10.

#### Example 9: Row Expansion

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)

New-UDTable -Data $Data -OnRowExpand {
    New-UDAlert -Text $EventData.Calories
} -Columns @(
    New-UDTableColumn -Title 'Dessert' -Property 'Dessert'
) -Id 'table9'
```

Row expansion can be enabled by setting the -OnRowExpand parameter to a scriptblock. The scriptblock will be passed the row data as a hashtable in the $EventData variable.

#### Example 10: Export

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)

$Columns = @(
    New-UDTableColumn -Property Dessert -Title "A Dessert" -IncludeInExport
    New-UDTableColumn -Property Calories -Title Calories  -IncludeInExport
    New-UDTableColumn -Property Fat -Title Fat   -IncludeInExport
    New-UDTableColumn -Property Carbs -Title Carbs   -IncludeInExport
    New-UDTableColumn -Property Protein -Title Protein   -IncludeInExport -Hidden
)

New-UDTable -Id 'table10' -Data $Data -Columns $Columns -Export
```

Export table data with the -Export parameter. You can configure which columns are included in the export by setting the -IncludeInExport parameter on the column. Use -Hidden to hide a column from the table but include it in the export.

#### Example 11: Text Options

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
)

$Option = New-UDTableTextOption -Search "Search all these records"

New-UDTable -Data $Data -TextOption $Option -ShowSearch -Id 'table11'
```

Text options can be used to customize the text in the table.

#### Example 12: Row Styling

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0 }
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0 }
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0 }
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0 }
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0 }
)

New-UDTable -Data $Data -OnRowStyle {
    if ($EventData.Dessert -eq 'Frozen yoghurt')
    {
        @{
            backgroundColor = "red"
        }
    } else {
        @{}
    }
} -Id 'table12'
```

You can style rows by using the -OnRowStyle parameter. The script block will be passed the row data as a hashtable in the $EventData variable. The script block should return a hashtable of CSS styles to apply to the row.

#### Example 13: Default Sort

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 1; Protein = 4.0 }
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 34; Protein = 4.0 }
    @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 73; Protein = 4.0 }
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 25; Protein = 4.0 }
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 99; Protein = 4.0 }
)
$Columns = @(
    New-UDTableColumn -Property Dessert -Title "Dessert"
    New-UDTableColumn -Property Calories -Title "Calories"
    New-UDTableColumn -Property Fat -Title "Fat"
    New-UDTableColumn -Property Carbs -Title "Carbs"  -DefaultSortColumn
    New-UDTableColumn -Property Protein -Title "Protein"
)
New-UDTable -Data $Data -DefaultSortDirection descending -Id 'table13' -ShowSort -Columns $Columns
```

Set the default sort direction and column.

#### Example 14: Initial state

```powershell
$Data = 1..100 | ForEach-Object {
    [PSCustomObject]@{
        Dessert = "Dessert $_"
        Calories = Get-Random -Minimum 100 -Maximum 500
        Fat = Get-Random -Minimum 1 -Maximum 10
        Carbs = Get-Random -Minimum 1 -Maximum 100
        Protein = Get-Random -Minimum 1 -Maximum 100
 }
}
$Columns = @(
    New-UDTableColumn -Property Dessert -Title "Dessert" -ShowFilter
    New-UDTableColumn -Property Calories -Title "Calories"
    New-UDTableColumn -Property Fat -Title "Fat"
    New-UDTableColumn -Property Carbs -Title "Carbs"
    New-UDTableColumn -Property Protein -Title "Protein"
)
 New-UDTable -Id 'table14'  -ShowPagination  -LoadData {
    foreach($Filter in $EventData.Filters)
    {
        $Data = $Data | Where-Object -Property $Filter.Id -Match -Value $Filter.Value
    }
    $TotalCount = $Data.Count
    if (-not [string]::IsNullOrEmpty($EventData.OrderBy))
    {
        $Descending = $EventData.OrderDirection -ne 'asc'
        $Data = $Data | Sort-Object -Property $EventData.orderBy.field -Descending:$Descending
    }

    $Data = $Data | Select-Object -First $EventData.PageSize -Skip ($EventData.Page * $EventData.PageSize)
    $Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties
} -Columns $Columns -InitialState @{
    pageIndex = 0
    pageSize = 20
    filters = @{
        id = "dessert"
        value = "20"
    }
    orderBy = @{ field = "fat" }
} -ShowSort
```

Set the initial state of the table. This can be used to set the page index, page size, filters, and order by column.

#### Example 15: Row coloring

```powershell
$Data = @(
    @{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 1; Protein = 4.0 }
    @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 150.0; Carbs = 34; Protein = 4.0 }
    @{Dessert = 'Eclair'; Calories = 159; Fat = 100.0; Carbs = 73; Protein = 4.0 }
    @{Dessert = 'Cupcake'; Calories = 159; Fat = 30.0; Carbs = 25; Protein = 4.0 }
    @{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 99; Protein = 4.0 }
)
$Columns = @(
    New-UDTableColumn -Property Dessert -Title "Dessert"
    New-UDTableColumn -Property Calories -Title "Calories"
    New-UDTableColumn -Property Fat -Title "Fat"
    New-UDTableColumn -Property Carbs -Title "Carbs"  -DefaultSortColumn
    New-UDTableColumn -Property Protein -Title "Protein"
)
New-UDTable -Data $Data -Id 'table14' -Columns $Columns -OnRowStyle {
    if ($EventData.Fat -lt 10) { $Color = 'green' }
    elseif ($EventData.Fat -ge 10 -and $EventData.Fat -lt 50) { $Color = 'Yellow' }
    else { $Color = 'Red' }
    @{ backgroundColor = $Color }
}
```

Use OnRowStyle to style rows based on the row data.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/powershell-commands/new-udtable.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
