# `Toddy.Iced.Widget.Table`
[🔗](https://github.com/toddy-ui/toddy-elixir/blob/v0.3.0/lib/toddy/iced/widget/table.ex#L1)

Data table -- composite widget built from columns, rows, and scrollable containers.

## Props

- `columns` (list of maps) -- column definitions. Each column is
  `%{key: string, label: string}`. The `key` maps to row data fields.
  Optional per-column fields:
  - `align` -- horizontal alignment for the column cells (`"left"`,
    `"center"`, `"right"`). Default: `"left"`.
  - `width` -- column width as a `Toddy.Iced.Length` value. Default: `:fill`.
  - `sortable` -- whether clicking the header triggers a sort event.
    Default: `false`.
- `rows` (list of maps) -- data rows. Each row is a map where keys
  correspond to column `key` values.
- `header` (boolean) -- show header row. Default: true.
- `separator` (boolean) -- show separator line below header. Default: true.
- `width` (length) -- table width. Default: fill. See `Toddy.Iced.Length`.
- `padding` (number | map) -- table padding. See `Toddy.Iced.Padding`.
- `sort_by` (string | nil) -- key of the currently sorted column.
- `sort_order` (`:asc` | `:desc` | nil) -- current sort direction.
- `header_text_size` (number) -- header row text size in pixels.
- `row_text_size` (number) -- body row text size in pixels.
- `cell_spacing` (number) -- horizontal spacing between cells in pixels.
- `row_spacing` (number) -- vertical spacing between rows in pixels.
- `separator_thickness` (number) -- separator line thickness in pixels.
- `separator_color` (color) -- separator line color. See `Toddy.Iced.Color`.
- `a11y` (map) -- accessibility overrides. See `Toddy.Iced.A11y`.

# `option`

```elixir
@type option() ::
  {:columns, [map()]}
  | {:rows, [map()]}
  | {:header, boolean()}
  | {:separator, boolean()}
  | {:width, Toddy.Iced.Length.t()}
  | {:padding, Toddy.Iced.Padding.t()}
  | {:sort_by, String.t()}
  | {:sort_order, sort_order()}
  | {:header_text_size, number()}
  | {:row_text_size, number()}
  | {:cell_spacing, number()}
  | {:row_spacing, number()}
  | {:separator_thickness, number()}
  | {:separator_color, Toddy.Iced.Color.input()}
  | {:a11y, Toddy.Iced.A11y.t()}
```

# `sort_order`

```elixir
@type sort_order() :: :desc | :asc
```

# `t`

```elixir
@type t() :: %Toddy.Iced.Widget.Table{
  a11y: Toddy.Iced.A11y.t() | nil,
  cell_spacing: number() | nil,
  columns: [map()] | nil,
  header: boolean() | nil,
  header_text_size: number() | nil,
  id: String.t(),
  padding: Toddy.Iced.Padding.t() | nil,
  row_spacing: number() | nil,
  row_text_size: number() | nil,
  rows: [map()] | nil,
  separator: boolean() | nil,
  separator_color: Toddy.Iced.Color.t() | nil,
  separator_thickness: number() | nil,
  sort_by: String.t() | nil,
  sort_order: sort_order() | nil,
  width: Toddy.Iced.Length.t() | nil
}
```

# `a11y`

```elixir
@spec a11y(table :: t(), a11y :: Toddy.Iced.A11y.t()) :: t()
```

Sets accessibility annotations.

# `build`

```elixir
@spec build(table :: t()) :: Toddy.Iced.ui_node()
```

Converts this table struct to a `ui_node()` map via the `Toddy.Iced.Widget` protocol.

# `cell_spacing`

```elixir
@spec cell_spacing(table :: t(), cell_spacing :: number()) :: t()
```

Sets the horizontal spacing between cells in pixels.

# `columns`

```elixir
@spec columns(table :: t(), columns :: [map()]) :: t()
```

Sets the column definitions.

# `header`

```elixir
@spec header(table :: t(), header :: boolean()) :: t()
```

Sets whether the header row is shown.

# `header_text_size`

```elixir
@spec header_text_size(table :: t(), header_text_size :: number()) :: t()
```

Sets the header text size in pixels.

# `new`

```elixir
@spec new(id :: String.t(), opts :: [option()]) :: t()
```

Creates a new table struct with optional keyword opts.

# `padding`

```elixir
@spec padding(table :: t(), padding :: Toddy.Iced.Padding.t()) :: t()
```

Sets the table padding.

# `row_spacing`

```elixir
@spec row_spacing(table :: t(), row_spacing :: number()) :: t()
```

Sets the vertical spacing between rows in pixels.

# `row_text_size`

```elixir
@spec row_text_size(table :: t(), row_text_size :: number()) :: t()
```

Sets the row text size in pixels.

# `rows`

```elixir
@spec rows(table :: t(), rows :: [map()]) :: t()
```

Sets the data rows.

# `separator`

```elixir
@spec separator(table :: t(), separator :: boolean()) :: t()
```

Sets whether the separator line is shown.

# `separator_color`

```elixir
@spec separator_color(table :: t(), separator_color :: Toddy.Iced.Color.input()) ::
  t()
```

Sets the separator line color.

# `separator_thickness`

```elixir
@spec separator_thickness(table :: t(), separator_thickness :: number()) :: t()
```

Sets the separator line thickness in pixels.

# `sort_by`

```elixir
@spec sort_by(table :: t(), sort_by :: String.t()) :: t()
```

Sets the currently sorted column key.

# `sort_order`

```elixir
@spec sort_order(table :: t(), sort_order :: sort_order()) :: t()
```

Sets the current sort direction.

# `width`

```elixir
@spec width(table :: t(), width :: Toddy.Iced.Length.t()) :: t()
```

Sets the table width.

# `with_options`

```elixir
@spec with_options(table :: t(), opts :: [option()]) :: t()
```

Applies keyword options to an existing table struct.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
