ExLiveTable.DataTable (ExLiveTable v0.1.0)

View Source

Provides helper functions for table sorting, pagination, and query string operations.

Summary

Functions

Handles the empty table state, displaying a loading spinner or "No data" message.

Renders a search input box that triggers an "iSearch" event on change.

Builds a query string from the current params and options. Used for pagination and sorting links.

Parses sort parameters from URL query parameters. Returns a tuple of {sort_direction, sort_field}.

Creates a table header link for sorting with proper direction switching.

Functions

empty_table(assigns)

Handles the empty table state, displaying a loading spinner or "No data" message.

Attributes

  • data_loader (:boolean) - Defaults to true.

isearch(assigns)

Renders a search input box that triggers an "iSearch" event on change.

Attributes

  • params (:map) - Defaults to %{"filter" => %{"isearch" => ""}}.

querystring(params, opts \\ %{})

Builds a query string from the current params and options. Used for pagination and sorting links.

Examples

iex> querystring(%{"page" => "1"}, sort_field: :name, sort_direction: "desc")
"page=1&sort_field=name&sort_direction=desc"

sort(other)

Parses sort parameters from URL query parameters. Returns a tuple of {sort_direction, sort_field}.

Examples

iex> sort(%{"sort_field" => "name", "sort_direction" => "asc"})
{:asc, :name}

iex> sort(%{"sort_field" => "created_at", "sort_direction" => "desc"})
{:desc, :created_at}

iex> sort(%{})
{:asc, :id}

table_link(params, text, field)

Creates a table header link for sorting with proper direction switching.

Examples

iex> table_link(%{"sort_field" => "name", "sort_direction" => "asc"}, "Name", :name)
# Returns a LiveView link to sort by name in desc order