Data display
Table
A data table from an array, a collection, a query or a model: column headers, rows, sorting by the URL, pagination, and per-column cell templates. It can add row selection, expandable rows, and columns the user can hide, reorder, resize and pin, remembered in the browser. For full control, the table parts can also be written by hand.
A table with Name, Email and Joined headers, 15 users per page and the pagination under it. Each header is a link that sorts by its column (?sortBy=email&sortDirection=asc), showing the direction and setting aria-sort; dates are shown in the app's locale, booleans as a check or a cross, and every value is escaped (an Htmlable value and a translate column's translation are printed as HTML). Inside a Livewire component, add the WithPagination trait to it: the page links call its setPage() and change the page without a reload.
Rows from data #
Rows can be arrays, models or a paginator. A column key reads the value with dot notation (customer.name); a <key>_formatted attribute on the row is used in place of <key> when it exists. A column named actions is narrow and centered, and a column named row_index shows the row's number on the page, from 1. Without cols, the columns come from the first row, or from the model (its visible, or fillable plus timestamps, attributes), leaving out id and anything that looks secret (password, token, api_key...).
|
Order
|
Customer
|
Total
|
|
|---|---|---|---|
|
#1042
|
Ana Souza
|
R$ 129,90
|
|
|
#1043
|
Bruno Reis
|
R$ 89,50
|
|
|
#1044
|
Caio Lima
|
R$ 340,00
|
|
|
#1045
|
Davi Luz
|
R$ 52,75
|
|
Nothing to show
Custom cells #
row_<key> replaces the content of that column's cells: a closure receives any of row, value (a closure returning the value: $value()), key, col, cols, rows and index by name; any other value is printed as is. col_<key> does the same for a header, its closure receiving any of col, key, name, cols and rows. Both can be written as row_name/col_name attributes or as <x-slot:col_name> slots.
Nothing to show
Cell templates in Blade #
@scope('row_<key>', $row) … @endscope writes the closure as Blade: its parameters are named as in row_<key> ($row, $value, $index...), and $errors is available inside it; other outer variables go in a third argument, @scope('row_name', ($row), ($team)). The name links to the user's page; the other columns render as usual.
|
Name
|
E-mail
|
|---|---|
|
No records found |
|
Nothing to show
Selection and expandable rows #
A checkbox column with a "select all" box in the header, and a chevron column that opens a full-width row of details under each row. selectedIds holds the id (or row-key) of the checked rows, across pages; the x-effect keeps $selected in sync with it, e.g. ['1', '3'].
|
|
|
Name
|
E-mail
|
|---|---|---|---|
|
No records found |
|||
Nothing to show
Totals and nested rows #
Each goal with a chevron before its name when it has children: the chevron shows its child rows under it, indented, and hides them again with their own children. The footer puts "Total" under Goal and the sum under Target, right aligned like the column, and follows the columns the user hides or moves.
|
Goal
|
Target
|
|---|---|
|
Training
|
120
|
|
Workshops
|
80
|
|
Online
|
30
|
|
Mentoring
|
40
|
|
Events
|
60
|
|
Fairs
|
60
|
|
Total
|
180
|
Nothing to show
Columns the user controls #
Each header gets a button to pin the column to the left, a grip to drag it to another place, an edge to resize it and a button to hide it. A "Show hidden columns" button appears while any is hidden. With persist, the choices are kept in the browser under that key.
|
No records found |
Nothing to show
Looks #
border, striped, hover and vertical-lines change the look; dense reduces the padding and :horizontal-lines='false' removes the lines between rows.
|
Order
|
Customer
|
Total
|
|---|---|---|
|
#1042
|
Ana Souza
|
R$ 129,90
|
|
#1043
|
Bruno Reis
|
R$ 89,50
|
|
#1044
|
Caio Lima
|
R$ 340,00
|
|
#1045
|
Davi Luz
|
R$ 52,75
|
|
Order
|
Customer
|
Total
|
|---|---|---|
|
#1042
|
Ana Souza
|
R$ 129,90
|
|
#1043
|
Bruno Reis
|
R$ 89,50
|
|
#1044
|
Caio Lima
|
R$ 340,00
|
|
#1045
|
Davi Luz
|
R$ 52,75
|
Nothing to show
Row numbers, alignment and actions #
A row_index column numbers the rows, a column given as an array takes props such as align, and an actions column is narrow and centered; here its cells call a Livewire action.
|
#
|
Order
|
Customer
|
Status
|
Total
|
|
|---|---|---|---|---|---|
|
1
|
#1042
|
Ana Souza
|
|
R$ 129,90
|
|
|
2
|
#1043
|
Bruno Reis
|
|
R$ 89,50
|
|
|
3
|
#1044
|
Caio Lima
|
|
R$ 340,00
|
|
|
4
|
#1045
|
Davi Luz
|
|
R$ 52,75
|
|
Nothing to show
Sticky header and columns #
sticky keeps the header at the top of a scroll area with a height (area:class); a column with 'sticky' => true stays in place while the table scrolls sideways.
|
Name
|
E-mail
|
Joined
|
|---|---|---|
|
No records found |
||
Nothing to show
Empty state and footer #
no-records sets the message when there are no rows; the footer slot adds a <tfoot> row spanning every column.
|
Order
|
Customer
|
|---|---|
|
No orders yet |
|
|
Order
|
Customer
|
Total
|
|---|---|---|
|
#1042
|
Ana Souza
|
R$ 129,90
|
|
#1043
|
Bruno Reis
|
R$ 89,50
|
|
#1044
|
Caio Lima
|
R$ 340,00
|
|
#1045
|
Davi Luz
|
R$ 52,75
|
|
4 orders · R$ 612,15
|
||
Nothing to show
Written by hand #
For full control, write tk:table.columns, tk:table.rows, tk:table.row, tk:table.cell and tk:table.footer yourself.
|
Customer
|
Total
|
|---|---|
|
Ana Souza |
R$ 129,90
|
|
Bruno Reis |
R$ 89,50
|
|
Caio Lima |
R$ 340,00
|
|
Davi Luz |
R$ 52,75
|
|
Prices include taxes.
|
Nothing to show
Customization #
Prefixes reach the parts: container: the outer box, column-<key>: one header, cell-<key>: one column's cells.
|
Order
|
Customer
|
Total
|
|---|---|---|
|
#1042
|
Ana Souza
|
R$ 129,90
|
|
#1043
|
Bruno Reis
|
R$ 89,50
|
|
#1044
|
Caio Lima
|
R$ 340,00
|
|
#1045
|
Davi Luz
|
R$ 52,75
|
Nothing to show
A column that is always shown #
With toggleable, a column given 'toggleable' => false has no hide button. The table fires column-toggled with the column name and whether it is visible.
|
Order
|
Customer
|
Status
|
Total
|
|---|---|---|---|
|
#1042
|
Ana Souza
|
paid
|
R$ 129,90
|
|
#1043
|
Bruno Reis
|
pending
|
R$ 89,50
|
|
#1044
|
Caio Lima
|
overdue
|
R$ 340,00
|
|
#1045
|
Davi Luz
|
paid
|
R$ 52,75
|
Nothing to show
Reference
tk:table
├── tk:table.columns
│ └── tk:table.column ...
├── tk:table.rows
│ └── tk:table.row
│ └── tk:table.cell ...
└── tk:table.footer
tk:table
| Prop | Type | Default | Description |
|---|---|---|---|
rows |
array | Collection | Paginator | query | model | null |
The rows. A query or model is paginated (15 per page). |
resource |
string | model | null |
A model class, its short name (user for App\Models\User) or an instance, used as rows. Any other class gives no rows. |
cols |
array | from the rows | The columns: key => label, a list of keys, or key => [props] (label, sortable, align, sticky, hidden, translate...). Give a column that is not a database column (an accessor) 'sortable' => false, so a query is not ordered by it, and one the user must always see 'toggleable' => false, so it has no hide button. |
sortable |
bool | false |
Makes every column but actions and related ones (customer.name) sortable through the URL (sortBy, sortDirection), and sorts a query by it. |
pagination |
bool | true |
false hides the pagination under the table. |
rowSelection |
bool | slot | false |
Adds a checkbox column. A slot replaces the checkbox in each row; give its checkbox data-role="row-selection" so the table tracks it. |
selectAll |
bool | slot | true with selection |
The header checkbox. false leaves the header cell empty; a slot replaces it. |
rowKey |
string | id |
The row attribute that identifies a row (data-id, wire:key, selection). |
rowExpanded |
Closure | slot | null |
Content of a details row under each row, opened by a chevron. A closure receives the row, the columns and the rows. Also expanded. |
noRecords |
string | slot | No records found |
The title of the empty state shown when there are no rows. |
footer |
array | slot | null |
An array puts each value under the column of the same key, aligned like it. A slot is a <tfoot> row spanning every column, or the cells written in it. |
tree |
bool | string | false |
Nests rows: each row's children (or the key given, tree="items") are rendered under it, hidden until its chevron is clicked. The key is left out of the default columns. Pagination and sorting apply to the top rows only. |
toggleable, draggable, resizable, pinnable |
bool | false |
Lets the user hide, reorder, resize or pin columns. |
persist |
string | null |
A key to keep the column choices in the browser. |
columnMinWidth, columnMaxMinWidth |
int | 80, 400 |
Width limits for resizing, in pixels. |
idColumn |
bool | false |
Keeps the id column when the columns come from the rows. |
mapRelationsColumn |
bool | true |
Shows user_id as the user relation. |
border, dense, striped, hover, verticalLines, horizontalLines, sticky |
bool | Looks: an outer border, less padding, striped rows, highlighted row on hover, lines between columns, lines between rows (on by default, false removes them), a header that sticks to the top of the scroll area: give the area a height for it to stick while the rows scroll (area:class="max-h-96"). |
row_<key> and col_<key> attributes or slots render custom cells and headers.
Slots
| Slot | Description |
|---|---|
| default | Table parts written by hand (<thead>, <tbody>, <tfoot>), in place of the generated ones. |
row_<key>, col_<key> |
A cell or header of that column. |
rowSelection, selectAll, rowExpanded, noRecords, footer |
As the props of the same name. |
cellExpanded |
Replaces the details button in each row; the element that opens the details needs data-role="row-expanded". |
Events
| Event | Detail | When |
|---|---|---|
ready |
The column features are set up. | |
column-toggled |
{ name, visible } |
The user hid or showed a column. |
Prefixes
| Prefix | Goes to |
|---|---|
container:, area: |
The outer box, and the horizontally scrollable area. |
columns:, column:, column-<key>: |
The header row, every header, one column's header. |
rows:, row: |
The <tbody>, every row. |
cell:, cell-<key>: |
Every cell, one column's cells (cell-total:class="text-end tabular-nums"). |
select-all:, cell-selection:, cell-expanded:, row-expanded: |
The selection and details parts; cell-expanded:button: reaches the details button, select-all:checkbox: and cell-selection:checkbox: the checkboxes. |
tree-button: |
The chevron of a row with children. |
no-records:, footer:, pagination: |
The empty row's cell, the footer, the pagination. Inside no-records:, empty: reaches the tk:empty (no-records:empty:icon="mdi:account-off"). |
hidden-columns:, show-columns: |
The bar and button for hidden columns. |
tk:table.column and tk:table.cell
For tables written by hand. tk:table.column: name, label, sortable (true, asc, desc), sortableHref, sortableAction, align, sticky, draggable, resizable, toggleable, pinnable, hidden, and a handle slot shown after the header's controls. tk:table.cell: align, label, sticky, column, toggleable, pinnable, hidden. Both take container: for the box inside the <th> or <td>. tk:table.columns, tk:table.rows, tk:table.row and tk:table.footer render <thead>, <tbody>, <tr> and <tfoot>.
Events
Dispatched on the <table>; do not bubble.
Customization
Classes and attributes on the tag go to the <table>. To reach the parts, prefix the attribute (listed in the Reference above).
Nothing to show
Accessibility
A native <table> with <th scope="col"> headers. Sortable headers are links and the sorted one has aria-sort. The selection checkboxes are named "Select row" and "Select all rows", and each row's checkbox and details button are described by the row's first data cell; "Select all rows" shows a mixed state when only some are checked. The details buttons are named "Row details" and the tree chevrons "Child rows"; both have aria-expanded and aria-controls and are described by the row's first data cell. When the table is wider than its area, the area takes the focus, named by the table's aria-label ("Table" without one), so it scrolls with the keyboard. Boolean cells have a visually hidden "Yes" or "No" next to the icon. The pin button is named "Pin column" or "Unpin column" and has aria-pressed; the hide button is named "Hide column". The resize edge is a focusable role="separator" named "Resize column", with the width as aria-valuenow.
| Key | Action |
|---|---|
| Arrow Left / Arrow Right | On the resize edge, narrows or widens the column by 10 px (swapped in right-to-left pages). |
| Shift + Arrow Left / Arrow Right | The same by 50 px. |
| Home | Narrows the column to its minimum width. |
| Enter | Fits the column to its content, as a double click does. |
Behavior notes
- A query is sorted only by a column listed in
cols(or a default column), so?sortBy=cannot order by an attribute the table does not show. A related column (customer.name) is never sortable, even with'sortable' => true. - Only an Eloquent query or model is sorted by the table. Rows given as a paginator, a collection or a
DB::table()query keep their order, though the headers still link to a sort: sort the query before paginating, e.g.TALLKit::applyTableSort(Order::query(), $cols)->paginate(). - The sort comes from the query string (
sortBy,sortDirection). In a Livewire update it is read from the URL the page was loaded with, with the component's#[Url]properties applied on top: a property is left out of the links only when it isnullor equal to itsexcept. To sort from component state, declare#[Url] public ?string $sortByand#[Url] public string $sortDirection. - Selection is kept across pages in
selectedIds, and cleared withresetSelection(). Rows that disappear from the page (deleted, or on another page) stay selected, so after a bulk action clear it from the server with$this->dispatch('tallkit:table-reset'), or$this->dispatch('tallkit:table-reset', id: 'users')for the table written as<tk:table id="users">. - A cell whose value is a model shows its
name,titleortext; a collection is shown as a list. - A tree keeps the rows the user opened across Livewire updates. Closing a row hides all the rows under it, and their details rows; opening it again shows them as they were left. With
toggleable, the first column, which holds the chevrons, cannot be hidden. - A template for a column named
key,selectionorexpandedis written asrow_key(notrowKey), since those camelCase names are the table's own props.