NAME

Chandra::Table - Sortable, filterable, paginated data grid component

SYNOPSIS

use Chandra::Table;

my $table = Chandra::Table->new(
    columns => [
        { key => 'name',  label => 'Name',  sortable => 1 },
        { key => 'email', label => 'Email', sortable => 1 },
        { key => 'role',  label => 'Role',  filterable => 1,
          filter_options => [qw(admin user guest)] },
    ],
    data      => \@users,
    page_size => 10,
    selectable => 'multi',
    on_row_click => sub { my ($row) = @_; print $row->{name} },
);

$app->css(Chandra::Table->css);
$table->mount($app, '#content');

DESCRIPTION

Chandra::Table is a Chandra::Component subclass providing a data grid. Renders using Chandra::Element for proper event wiring.

METHODS

new(columns = \@columns, data => \@rows, %options)>

A column is a hash with a key, a label, and any of sortable, filterable, filter_options, width, type (boolean) and render (a code reference given the value and the row). The options are page_size, selectable (single or multi), striped, empty_message, loading, on_row_click, on_sort and on_selection.

set_data(\@rows)

Replaces the rows, goes back to the first page, clears the selection and updates when mounted.

selected_rows

The indexes of the selected rows on the current page.

on_sort_column($key)

Sorts by that column, flipping the direction on the same column again.

on_filter($key, $value)

Filters a column, or clears its filter when the value is empty.

on_page($page)

Goes to that page, clamped to the pages there are.

on_select_row($index)

Selects a row, replacing the selection in single mode and toggling it in multi mode.

on_click_row($index)

Runs on_row_click with the row.

on_select_all

Selects every row on the page, or clears them when they all are.

to_csv

The sorted rows as CSV, quoting as needed.

render

The filters, the table and its pagination.

css

The table's stylesheet.

prototype, set_prototype

Object::Proto's prototype accessors.

SLOT ACCESSORS

columns, data, page_size, selectable, striped, on_row_click, on_sort, on_selection, empty_message, loading - the slots as methods
tbl_columns, tbl_data, tbl_page_size, tbl_selectable, tbl_striped, tbl_on_row_click, tbl_on_sort, tbl_on_selection, tbl_empty_message, tbl_loading, tbl__current_page, tbl__sort_key, tbl__sort_dir, tbl__filters, tbl__selected, tbl__cid, tbl__app, tbl__selector, tbl__mounted, tbl__children, tbl__parent - the slot functions

SEE ALSO

Chandra::Component, Chandra::Element, Chandra::App