Cards
Besides the table, a list can show its records as cards – handy on phones
and for records with few, meaningful values. Users switch with the view
switch of the toolbar; views() decides which views exist.
->card( title: 'name', // heading, links to the detail page description: 'cost_center_id', // small line under the title badges: ['department'], // next to the title meta: ['birth_on', 'entry_on', 'exit_on'], // one line, side by side; icons instead of labels rows: [['hint'], ['ad_users', 'devices']], // lines of 1 to 4 labelled values fields: ['phone'], // label and value per line)| Area | Shows |
|---|---|
title |
the heading; links to the detail page if the user may view the record |
description |
a small line under the title |
badges |
values next to the title, e.g. a status badge |
meta |
one line of values side by side, each with the icon of its column instead of a label |
rows |
lines of 1 to 4 values, each with its label |
fields |
one value per line with its label |
Every area takes column names of the collection:
- Columns the user has hidden are left out; unknown names are ignored.
- Values keep their format, colour, icon and link (
render()); thedescription()of a column is shown in the table only. - Without
card()the first column is the title and the others are fields. - Without
badges,metaandrows,fieldsdefaults to the columns that are not title or description; with one of them and nofields, there are no fields.
The tone of a record colours its card (border on the left, light background). The actions of the record are at the bottom, see Actions in lists.
$collection->views([Collection::VIEW_TABLE, Collection::VIEW_CARDS], default: Collection::VIEW_CARDS);$collection->views([Collection::VIEW_CARDS]); // cards only, no switchThe chosen view is remembered per user and list.
Own card view
Section titled “Own card view”card(view: 'employees/card') replaces the card of this collection with
an own view. It receives:
| Variable | Content |
|---|---|
$record |
the record |
$resource, $collection |
the resource and the collection |
$columns |
the visible columns |
$actions |
HTML of the record actions |
$tone |
the tone of the record or null |
$selectable |
whether the record can be selected for bulk actions |
Render values with $column->render($record) (escaped, with icon, colour
and link) and escape everything else with esc(). No inline styles or
scripts.