# `Kino.Table`
[🔗](https://github.com/livebook-dev/kino/blob/v0.19.0/lib/kino/table.ex#L1)

A behaviour module for implementing tabular kinos.

This module implements table visualization and delegates data
fetching and traversal to the behaviour implementation.

# `column`

```elixir
@type column() :: %{
  :key =&gt; term(),
  :label =&gt; String.t(),
  optional(:type) =&gt; type(),
  optional(:summary) =&gt; %{required(String.t()) =&gt; String.t()}
}
```

# `info`

```elixir
@type info() :: %{
  :name =&gt; String.t(),
  :features =&gt; [:export | :refetch | :pagination | :sorting | :relocate],
  optional(:export) =&gt; %{formats: [String.t()]},
  optional(:num_rows) =&gt; pos_integer()
}
```

# `rows_spec`

```elixir
@type rows_spec() :: %{
  offset: non_neg_integer(),
  limit: pos_integer(),
  order: nil | %{direction: :asc | :desc, key: term()},
  relocates: [%{from_index: non_neg_integer(), to_index: non_neg_integer()}]
}
```

# `state`

```elixir
@type state() :: term()
```

# `t`

```elixir
@type t() :: Kino.JS.Live.t()
```

# `type`

```elixir
@type type() :: String.t()
```

The following types have meaning on the front-end:

  * "date"
  * "list"
  * "number"
  * "struct"
  * "text"
  * "uri"

# `export_data`
*optional* 

```elixir
@callback export_data(rows_spec(), state(), String.t()) ::
  {:ok, %{data: binary(), extension: String.t(), type: String.t()}}
```

Exports the data for download.

The returned map must contain the binary, the file extension and the mime type.

# `get_data`

```elixir
@callback get_data(rows_spec(), state()) ::
  {:ok,
   %{
     columns: [column()],
     data: {:columns | :rows, [[String.t()]]},
     total_rows: non_neg_integer() | nil
   }, state()}
```

Loads data matching the given specification.

# `init`

```elixir
@callback init(init_arg :: term()) :: {:ok, info(), state()}
```

Invoked once to initialize server state.

# `on_update`
*optional* 

```elixir
@callback on_update(update_arg :: term(), state :: state()) :: {:ok, state()}
```

Invoked to update state with new data.

This callback is called in response to `update/2`.

# `new`

```elixir
@spec new(module(), term(), keyword()) :: t()
```

Creates a new tabular kino using the given module as data
specification.

## Options

  * `:export` - a function called to export the given kino to Markdown.
    This works the same as `Kino.JS.new/3`, except the function
    receives the state as an argument

# `update`

```elixir
@spec update(t(), term()) :: :ok
```

Updates the table with new data.

An arbitrary update event can be used and it is then handled by
the `c:on_update/2` callback.

---

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