table() reference

35 entries for 44 methods. Each entry runs its example on this page and shows its code.

Table

auto()Add a text column for every field of the data, with edit, delete and active buttons unless told otherwise.
htmx()Sort headers, a live filter and a pager or "load more" row that htmx swaps without reloading the page.
render()Render the table to HTML (or JSON); the table options passed to table() or here decide paging, layout and the empty case.
table($data, $params)Start a table: rows from an array, an SQL query, a query builder or a callback, then one call per column, button or link.
tpl_row()Add a column by the name of its method, the form a template or a config array can hold.

Columns

admin()Show admin ids as "id; login", linked to the admin account.
allow_deny()Show a 0 / 1 field as a disabled Allow or Deny button.
Common column optionsOptions every column method takes in its $extra array: header, width, tips, cell attributes, transforms and visibility.
data()Show a comma-separated list of ids as their names, one per line.
date()A date column: a timestamp or a date string formatted with _format_date().
func()A column whose cells your callback renders from the value and the whole row.
icon()Show an icon from an icon class name (icon-*) or an image file of uploads/icons/.
image()An image column: the path pattern is filled from the row id, the file is checked, and the image links to itself.
lang()Show a language code with the flag of its default country.
link()A column whose cells link somewhere, with the link and the value => text data as arguments.
rownum()A row counter column that continues across pages (row 21 on page 2 of 20).
stars()Show a rating as a row of star icons.
text()A column that prints one field of each row as text, optionally as a link, translated, shortened or with a badge.
text_padded()A text column indented by the level of the row, for trees such as categories or menus.
user()Show user ids as links with the login (or name, email, phone) of each user, loaded in one query.
yes_no()Show a 0 / 1 field as a disabled Yes or No button.

Row buttons

btn()A button (link) in the actions column of every row; %d and %<field> in the link come from the row.
btn_active()An Active / Inactive toggle in each row, showing the state of the row field named after the button (active).
btn_edit(), btn_view(), btn_clone(), btn_delete()The usual row buttons, each a btn() with its own default link, icon and admin class.
btn_func()A cell of the actions column rendered by your callback, for buttons that need the whole row.

Header and footer

footer_add(), header_add()The Add button below or above the table: a footer_link() with the add link, icon and ajax class.
footer_link(), header_link()A link button below (footer_link) or above (header_link) the table.
footer_submit(), header_submit()A submit button below or above a table that holds a form (inputs, check boxes in the rows).

Form controls in rows

check_box()A check box in each row, posting field[value] (usually the ids of the rows to act on).
form()Wrap the table in a form, so inputs, check boxes and selects in its rows post together.
input(), input_padded()A text input in each row, named field[row id], to edit one field of many rows at once; input_padded() indents tree rows.
radio_box()A group of radio buttons in each row, posting field[value] = the picked choice for every row.
select_box()A drop-down in each row, posting field[value].

Rows and events

on_post(), on_before_render(), on_after_render()Callbacks around rendering: on a POST before the rows are drawn, before rendering with the data, after rendering with the HTML.
tr(), td()Register row and cell callbacks that add attributes; applied only with the TR_TD_CALLBACKS flag, otherwise use the tr and td table options.

Demos