View Source Kino.Table behaviour (Kino v0.10.0)

A behaviour module for implementing tabular kinos.

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

Link to this section Summary

Callbacks

Exports the data for download.

Loads data matching the given specification.

Invoked once to initialize server state.

Functions

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

Link to this section Types

@type column() :: %{
  :key => term(),
  :label => String.t(),
  optional(:type) => String.t(),
  optional(:summary) => %{required(String.t()) => String.t()}
}
@type info() :: %{
  :name => String.t(),
  :features => [:export | :refetch | :pagination | :sorting],
  optional(:export) => %{formats: [String.t()]}
}
@type rows_spec() :: %{
  offset: non_neg_integer(),
  limit: pos_integer(),
  order: nil | %{direction: :asc | :desc, key: term()}
}
@type state() :: term()
@type t() :: Kino.JS.Live.t()

Link to this section Callbacks

Link to this callback

export_data(state, t)

View Source (optional)
@callback export_data(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.

Link to this callback

get_data(rows_spec, state)

View Source
@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.

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

Invoked once to initialize server state.

Link to this section Functions

@spec new(module(), term()) :: t()

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