Beacon.LiveAdmin.PageBuilder.Table (Beacon LiveAdmin v0.4.2)

View Source

Represents a Table in the LiveAdmin UI, with pagination, filtering, and sorting.

Summary

Functions

Initializes a new Table struct.

Generates a path to navigate from the current page to another given page.

Updates the current page based on incoming params and a count_fn which returns the number of items which have already been seen.

Generates a path for the next page of a paginated table.

Generates a path for the previous page of a paginated table.

Creates a list of query params based on the existing params in a given table and a new set of incoming params.

Pushes updated Table data to the websocket.

Types

t()

@type t() :: %Beacon.LiveAdmin.PageBuilder.Table{
  current_page: integer(),
  page_count: integer(),
  per_page: integer(),
  query: String.t(),
  sort_by: atom()
}

Functions

build(opts)

@spec build(keyword()) :: t()
@spec build(term()) :: nil

Initializes a new Table struct.

Options

  • sort_by - (required) the field on which to sort the table contents
  • per_page - the number of items to display per page (defaults to 15)

goto_path(socket, page, page)

Generates a path to navigate from the current page to another given page.

If the current and goto pages are the same, it will still append table params to the path.

Usage

<.link patch={Table.goto_path(@socket, @page)}>

handle_params(socket, params, count_fn)

Updates the current page based on incoming params and a count_fn which returns the number of items which have already been seen.

Can be called as a helper inside a Beacon.LiveAdmin.PageBuilder.handle_params/3 callback when updating params for a Table.

next_path(socket, page)

Generates a path for the next page of a paginated table.

Usage

<.link patch={Table.next_path(@socket, @page)}>

prev_path(socket, page)

Generates a path for the previous page of a paginated table.

Usage

<.link patch={Table.prev_path(@socket, @page)}>

query_params(table, new_params)

@spec query_params(
  t(),
  keyword()
) :: map()

Creates a list of query params based on the existing params in a given table and a new set of incoming params.

The existing and incoming params will be merged, with precedence for the latter (incoming will overwrite existing).

update(socket, new_table)

Pushes updated Table data to the websocket.

The Beacon Page containing the table will be automatically updated