Skip to main content

Columns

Every field you will define will automatically be converted to a Qore\System\Table\Column when a table is loaded. A column defines the way data should be shown in your table.

Usage

You can change the alignment for your column:

Text::make(__('First name'), 'first_name')
->setColumnAlignment('right')

You can define a width:

Text::make(__('Last name'), 'last_name')
->setColumnWidth(100) // OR: ->setColumnWidth('md')

Adding header styles:

Text::make(__('Last name'), 'last_name')
->setColumnHeaderStyle('color: green; font-weight: bold;')

Conditional styling

You can add specific styling to a table row or a column based on conditions.

For example, you may want to set the text color to green for a specific price:

Text::make(__('First name'), 'first_name')
->setColumnStyle(function(TableDataStyler $styler, Model $model) {
if ($model->first_name === 'Willem') {
$styler->setColumnStyle('font-weight: bold; background-color: yellow;');
}

if ($model->id == 494 || $model->id === 505) {
$styler->setRowStyle('background-color: lightgreen');
}

if ($model->id === 501) {
$styler->setRowClass('bg-red-2');
}

if ($model->id === 498) {
$styler->setRowClass('bg-green-2 text-bold');
}

if ($model->email === 'ayden53@yahoo.nl') {
$styler->setColumnClass('text-bold');
}

if ($model->id === 490) {
$styler->setRowClass('text-bold');
}
})
info

If you want to style a particular row regardless of whether a column/field is visible, you can override the postProcessTableRow method on your resource, or postProcessRow on the Table class if you don't have a resource.

See also Table row styling for more information

Table totals

Fields like Number and Price will show totals for the current page, and for all the pages. You can add your custom summaries for each field:

Text::make(__('Last name'), 'last_name')
->summarizeUsing(function (Builder $query) {
return [
[
'value' => $query->sum('id'),
'label' => __('My custom number'),
'formatter' => 'number'
],
[
'value' => $query->avg('id'),
'label' => __('My custom price'),
'formatter' => 'price'
],
[
'value' => $query->toSql(),
'label' => __('My custom text'),
'formatter' => 'text'
]
];
}, 'total_test')

The total_test is the unique SELECT key used in the query. You should supply an unreserved identifier here. At this time of writing, the selected formatters are number, price and text


You can disable totals by chaining this on your field/column:

->withoutSummary()