In the table configuration you define all the columns of the table
All Options are as constants in Table class.
title: String|Nullsearchable: Boolean, default: falsesortable: Boolean, default: trueattr:table_attr:default_limit : Int, dafault: 25limit_choices: Int, possible values: [10, 25, 50, 100, 200]table_box_template: String, box template, default: [@araiseTable](https://github.com/araiseTable)/table.html.twigtable_template: String, table template, default: [@araiseTable](https://github.com/araiseTable)/tableOnly.html.twigdefault_sort:content_visibility: Array with option, default:content_show_pagination: Boolean, default: truecontent_show_result_label: Boolean, default: truecontent_show_header: Boolean, default: truecontent_show_entry_dropdown: Boolean, default: truecontent_show_pagination_if_page_total_less_than_limit: Boolean, default: truesub_table_collapsed: Boolean or callable, default: trueBy default, sub-tables will be rendered collapsed.
This can be changed by setting the sub_table_collapsed option to either false or pass a callable that returns a boolean.
$table->setOption(Table::OPT_SUB_TABLE_COLLAPSED, false);
Note that if you pass a function, you will get the current row as an argument. You can use this to only expand certain rows:
// Expand only users with an email
$table->setOption(Table::OPT_SUB_TABLE_COLLAPSED, function(array|object $row) {
if(!$row instanceof User) {
return true;
}
if($row->getEmail() !== null) {
return false;
}
return true;
});
Example
$table
->addColumn('firstname')
->addColumn('lastname')
->addColumn('birthday', null, [
'sortable' => false,
'formatter' => UserBirthdayFormatter::class,
])
;
For the columns you have a few options to tweak how they behave:
All Options are as constants in Column class.
label: String, column namecallable: Function, callable to get the dataaccessor_path: String, defaults to the acronymformatter: Formattersort_expression: String, example: 'trainerGroup.name'In this example we would like to add a count of the content at the end of our table. We can to this by adding a footer column like so:
$data= [
[
'id' => 1,
],
[
'id' => 2,
]
];
$table
->setFooterData(['count' => count($data)])
->addFooterColumn('totalLabel', null, [
Column::OPT_CALLABLE => fn (array $content) => 'Total',
])
->addFooterColumn('count', null, [
Column::OPT_CALLABLE => fn(array $content) => $content['count'],
])
;
Note that this is only a simple example. The data could easily be replaced with an array of entities for example.
Action Columns are here to link to other pages (f.ex. link to edit or view). This column has a special template to render the links.
You can add your own table actions like this:
$table->addAction('test', [
Action::OPT_LABEL => 'Test Button',
Action::OPT_ROUTE => self::getRoute(Page::SHOW),
Action::OPT_ROUTE_PARAMETERS => fn ($row) => [
'id' => $row->getId(),
],
]);
As per default, the addAction()-method will use the Action class for your configuration.
To change which rows can use an action, try using the TableAction class and its visibility option instead:
$table->addAction('test', [
Action::OPT_LABEL => 'Test Button',
Action::OPT_ROUTE => self::getRoute(Page::SHOW),
Action::OPT_ROUTE_PARAMETERS => fn ($row) => [
'id' => $row->getId(),
],
TableAction::OPT_VISIBILITY => fn($row) => $row->getId() % 2 === 0,
], TableAction::class);
You can also simply set the visibility to a boolean instead of giving it a function:
TableAction::OPT_VISIBILITY => false
Take a look at the constants on the Action or the TableAction class.
You can use all of these to further configure your action.
Our tables can be filtered very easily. Most of it works automatically. See chapter Filters for more info.
How can I help you explore Laravel packages today?