- Creating Columns
- Relationships
- Available Methods
- Other Column Types
- Column Selection
- Secondary Header
- Footer
Getting Started
Usage
DataTable
Columns
Rows
Sorting
Pagination
Search
Bulk Actions
Filters
Reordering
Secondary Header
Footer
Examples
Misc.
This is the documentation for v2. You can switch versions in the menu on the left/at the top. Check your current version with the following command:
composer show rappasoft/laravel-livewire-tables
Creating Columns
The columns
method on your component must return an array of Column objects in the order you wish to see them on the table:
public function columns(): array
{
return [
Column::make('Name'),
Column::make('Email'),
];
}
Setting field names
By default, you only need one parameter which acts as the header of the column, the field which it references will be acquired using Str::snake
.
So if you have:
public function columns(): array
{
return [
Column::make('Name'), // Looks for column `name`
Column::make('Email'), // Looks for column `email`
];
}
Of course, this won't work in every situation, for example if you have an ID column, Str::snake will convert it to i_d
which is incorrect. For this situation and any other situation where you want to specify the field name, you can pass it as the second parameter:
public function columns(): array
{
return [
Column::make('ID', 'id'),
Column::make('E-mail', 'email'),
];
}