> 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/da/powershell-kommandoer/new-udtable.md).

# New-UDTable

New-UDTable opbygger en datatabel i PowerShell Universal med sortering, filtrering, søgning, sideinddeling og support til dataindlæsning på serversiden.

### Synopsis

Opretter en tabel.

### Syntaks

```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>]
```

### Beskrivelse

Opretter en tabel. Tabeller bruges til at vise både statiske og dynamiske data. De kan definere kolonner og data, der skal vises i tabellen. Kolonnerne kan bruges til at gengive brugerdefinerede komponenter baseret på rækkedata. De kan også aktivere sideopdeling, filtrering, sortering og endda behandling på serversiden.

### Parametre

#### -Id

Id for komponenten. Standardværdien er et tilfældigt GUID.

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

#### -Title

Titlen, der skal vises øverst på tabellens kort.

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

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

De data, der skal lægges i tabellen.

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

#### -LoadRows

Når der bruges dynamiske tabeller, kaldes denne scriptblok. Parameteren $Body indeholder en hashtable med følgende valgmuligheder:

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

De kan bruge disse værdier til at udføre behandling på serversiden, f.eks. SQL-forespørgsler, for at forbedre ydeevnen for store gitre.

Efter behandling af dataene med disse værdier skal De udskrive dataene via Out-UDTableData.

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

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

Definerer de kolonner, der skal vises i tabellen. Brug New-UDTableColumn til at definere disse kolonner. Hvis denne parameter ikke er angivet, bliver egenskaberne for de data, De sender ind, til kolonnerne.

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

#### -OnRowSelection

En scriptblok, der kaldes, når en række vælges. $EventData vil indeholde de valgte rækker.

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

#### -ShowSort

Om sorteringskontrolelementer skal vises på kolonner

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

#### -ShowFilter

Om der skal vises filterkontroller på kolonner

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

#### -ShowSearch

Om fuld tabelsøgning skal vises

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

#### -Dense

Reducerer det mellemrum, der bruges i tabellen.

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

#### -ShowExport

Om eksportknappen skal vises.

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

#### -StickyHeader

Gør headeren klæbende.

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

#### -PageSize

Standardsidestørrelsen.

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

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

Et array af tilgængelige valgmuligheder for sidestørrelse.

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

#### -PaginationLocation

Hvor sideinddelingskontrolelementerne skal vises. Gyldige værdier er top, bottom eller both. Standard er bottom.

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

#### -ShowSelection

Om markering i tabellen skal tillades.

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

#### -ShowPagination

Om sideinddelingskontrolelementer skal vises.

```
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

Tabellens størrelse. Standardværdien er medium. Gyldige værdier er medium og small.

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

#### -TextOption

Tilpasninger af standardteksten i tabellen. Brug New-UDTextOption til at oprette tekstindstillingerne.

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

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

Et array af eksportmuligheder.

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

#### -OnExport

En scriptblok, der bruges til at tilpasse, hvordan eksporten udføres.

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

#### -DisablePageSizeAll

Fjerner indstillingen All fra valgmulighederne for sidestørrelse.

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

#### -DefaultSortDirection

Standardsorteringsretningen.

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

#### -HideToggleAllRowsSelected

Skjuler knappen, der slår markering af alle rækker til eller fra.

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

#### -DisableMultiSelect

Deaktiverer flervalg.

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

#### -DisableSortRemove

Fjerner sorteringsmuligheden for usorterede kolonner. Kolonner vil altid være stigende eller faldende.

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

#### -Icon

Sætter et ikon ved siden af titlen. Brug New-UDIcon til at oprette ikonet.

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

#### -ClassName

En CSS-klasse, der skal anvendes på tabellen.

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

#### -ShowRefresh

Om opdateringsknappen skal vises.

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

#### -ToolbarContent

Brugerdefineret indhold, der skal vises på værktøjslinjen.

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

#### -OnRowExpand

En scriptblok, der kaldes, når en række udvides. Variablen $EventData vil indeholde rækkedataene.

```
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

Genindlæser tabellen med et interval, når -LoadRows bruges.

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

#### -AutoRefreshInterval

Intervallet for genindlæsning af data, når AutoRefresh er angivet.

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

#### -Language

Sproget. Bruges primært til dato- og klokkeslætsfiltre.

```
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

En scriptblok, der kaldes for at angive typografi for rækker. Variablen $EventData vil indeholde rækkedataene.

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

#### -HeaderStyle

En hashtable med typografier, der skal anvendes på headeren.

```
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
```

#### Fælles parametre

Denne cmdlet understøtter de fælles parametre: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable og OutVariable. Se [about\_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216) for at få flere oplysninger.

### Output

### Eksempler

#### Eksempel 1: grundlæggende tabel

```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'
```

Opretter en statisk tabel, hvor kolonnerne i tabellen er egenskaberne for de angivne data.

#### Eksempel 2: kolonner

```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'
```

Opretter en tabel, hvor der er defineret brugerdefinerede kolonner til tabellen.

#### Eksempel 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'
```

Opretter en tabel, hvor kolonnerne gengives med brugerdefineret indhold.

#### Eksempel 4: kolonnebredde

```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'
```

Angiv brugerdefineret kolonnebredde

#### Eksempel 5: kolonnefilter

```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
```

Kolonnefiltre til en tabel

#### Eksempel 6: kolonnesøgning

```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
```

Kolonner kan medtages i søgningen

#### Eksempel 7: behandling på serversiden

```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'
```

Behandling på serversiden er nyttig til store datasæt, der ikke bør indlæses i browseren.

#### Eksempel 8: sideinddeling

```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'
```

Sideinddeling kan aktiveres ved at angive parameteren -Paging til $true. Standardsidestørrelsen er 10.

#### Eksempel 9: rækkeudvidelse

```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'
```

Rækkeudvidelse kan aktiveres ved at angive parameteren -OnRowExpand til en scriptblok. Scriptblokken modtager rækkedataene som en hashtable i variablen $EventData.

#### Eksempel 10: eksport

```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
```

Eksportér tabeldata med parameteren -Export. De kan konfigurere, hvilke kolonner der medtages i eksporten, ved at angive parameteren -IncludeInExport på kolonnen. Brug -Hidden til at skjule en kolonne i tabellen, men medtage den i eksporten.

#### Eksempel 11: tekstindstillinger

```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'
```

Tekstindstillinger kan bruges til at tilpasse teksten i tabellen.

#### Eksempel 12: typografi for rækker

```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'
```

De kan angive typografi for rækker ved hjælp af parameteren -OnRowStyle. Scriptblokken modtager rækkedata som en hashtable i variablen $EventData. Scriptblokken skal returnere en hashtable med CSS-typografier, der skal anvendes på rækken.

#### Eksempel 13: standardsortering

```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
```

Angiv standardsorteringsretningen og -kolonnen.

#### Eksempel 14: starttilstand

```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
```

Angiv tabellens starttilstand. Dette kan bruges til at angive sideindeks, sidestørrelse, filtre og rækkefølge efter kolonne.

#### Eksempel 15: farvelægning af rækker

```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 }
}
```

Brug OnRowStyle til at formatere rækker ud fra rækkedataene.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
