-
Notifications
You must be signed in to change notification settings - Fork 28
Columns
Column is responsible for displaying a data in the data grid. It also orders data.
Columns are defined under columns
method in entity's schema.
You will most likely use one type of columns -- Proxy
. This type of column just
references a field to extract and format data. This column is defined this way:
$s->col('name');
Now you will have a column that will display the value of the field name
.
You can specify which field to use directly:
$s->col('foo', 'bar');
To specify multiple columns:
$s->cols([ 'id', 'name', 'foo' => 'bar' ]);
Sometimes you need to display non-ordinary data. Computed columns come in handy. You can specify a closure for extracting a data:
You can specify a clause to allow ordering:
$s->compute('full_name', ...)->clause(DB::raw('concat(first_name, last_name)'));
By default, column is formatted using a field that the column refers to, but there
are cases when you need to override this behaviour. Formatter is a JavaScript class
under Cruddy.Formatters
namespace that is responsible for converting column's value
to the string representation.
$s->col('avatar')->format('Image', [ 'width' => 150 ]);
To display data as is (allowing HTML tags), you can use Plain
formatter:
$s->col('foo')->format('Plain');
Image
formatter inserts a thumbnail into the data grid:
$s->col('image')->format('Image', $options);
Where $options
is an array of following options:
-
width
-- maximum width of the thumbnail -
height
-- maximum height of the thumbnail
Options are completely optional.
The default order direction is ascending. You can reverse it:
$s->col('name')->reversed();