# Tables

Tables can be used to display data to users in a grid format.

## Basic Table

Tables consist of a data source and a series of columns. You can use PowerShell variables are a data source. A simple script could load all the services on the machine into a variable.

```powershell
$Variables["Services"] = Get-Service
```

The table would then display a set number of properties as columns.

```markup
<Table DataSource="$Services">
    <PropertyColumn Property="Name"></PropertyColumn>
    <PropertyColumn Property="Status"></PropertyColumn>
</Table>
```

## Column Content

Property columns can provide custom content based on the row being rendered. Use the `$Context` variable to reference the current row.

```markup
<Table DataSource="$Services">
    <PropertyColumn Property="Name"></PropertyColumn>
    <PropertyColumn Property="Status">
        <Alert Message="$context.Status" />
    </PropertyColumn>
</Table>
```

## Action Columns

Actions columns are not tied to a particular property and are used for display actions such as buttons.

```markup
<Table DataSource="$Services">
    <PropertyColumn Property="Name"></PropertyColumn>
    <PropertyColumn Property="Status">
        <Alert Message="$context.Status" />
    </PropertyColumn>
    <ActionColumn>
        <Button OnClick="ShowStatus">Show Status</Button>
    </ActionColumn>
</Table>
```

To reference the current row in the button click, use the `$Context` parameter.

```powershell
function ShowStatus {
    param($Context)
    $Message.Success($Context.Status.ToString())
}
```


---

# Agent Instructions: 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:

```
GET https://docs.powershelluniversal.com/portal/portal-widgets/tables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
