Advanced
Pagination
Disabling pagination
By default, tables will be paginated. To disable this, you should use the $table->paginated(false)
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->paginated(false);
}
Customizing the pagination options
You may customize the options for the paginated records per page select by passing them to the paginated()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->paginated([10, 25, 50, 100, 'all']);
}
Customizing the default pagination page option
To customize the default number of records shown use the defaultPaginationPageOption()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->defaultPaginationPageOption(25);
}
Preventing query string conflicts with the pagination page
By default, Livewire stores the pagination state in a page
parameter of the URL query string. If you have multiple tables on the same page, this will mean that the pagination state of one table may be overwritten by the state of another table.
To fix this, you may define a $table->queryStringIdentifier()
, to return a unique query string identifier for that table:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->queryStringIdentifier('users');
}
Displaying links to the first and the last pagination page
To add "extreme" links to the first and the last page using the extremePaginationLinks()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->extremePaginationLinks();
}
Using simple pagination
You may use simple pagination by overriding paginateTableQuery()
method.
First, locate your Livewire component. If you're using a resource from the Panel Builder and you want to add simple pagination to the List page, you'll want to open the Pages/List.php
file in the resource, not the resource class itself.
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
protected function paginateTableQuery(Builder $query): Paginator
{
return $query->simplePaginate(($this->getTableRecordsPerPage() === 'all') ? $query->count() : $this->getTableRecordsPerPage());
}
Using cursor pagination
You may use cursor pagination by overriding paginateTableQuery()
method.
First, locate your Livewire component. If you're using a resource from the Panel Builder and you want to add simple pagination to the List page, you'll want to open the Pages/List.php
file in the resource, not the resource class itself.
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Database\Eloquent\Builder;
protected function paginateTableQuery(Builder $query): CursorPaginator
{
return $query->cursorPaginate(($this->getTableRecordsPerPage() === 'all') ? $query->count() : $this->getTableRecordsPerPage());
}
Record URLs (clickable rows)
You may allow table rows to be completely clickable by using the $table->recordUrl()
method:
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
public function table(Table $table): Table
{
return $table
->recordUrl(
fn (Model $record): string => route('posts.edit', ['record' => $record]),
);
}
In this example, clicking on each post will take you to the posts.edit
route.
If you'd like to override the URL for a specific column, or instead run an action when a column is clicked, see the columns documentation.
Reordering records
To allow the user to reorder records using drag and drop in your table, you can use the $table->reorderable()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->reorderable('sort');
}
If you're using mass assignment protection on your model, you will also need to add the sort
attribute to the $fillable
array there.
When making the table reorderable, a new button will be available on the table to toggle reordering.
The reorderable()
method accepts the name of a column to store the record order in. If you use something like spatie/eloquent-sortable
with an order column such as order_column
, you may use this instead:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->reorderable('order_column');
}
The reorderable()
method also accepts a boolean condition as its second parameter, allowing you to conditionally enable reordering:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->reorderable('sort', auth()->user()->isAdmin());
}
Enabling pagination while reordering
Pagination will be disabled in reorder mode to allow you to move records between pages. It is generally bad UX to re-enable pagination while reordering, but if you are sure then you can use $table->paginatedWhileReordering()
:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->paginatedWhileReordering();
}
Customizing the reordering trigger action
To customize the reordering trigger button, you may use the reorderRecordsTriggerAction()
method, passing a closure that returns an action. All methods that are available to customize action trigger buttons can be used:
use Filament\Tables\Actions\Action;
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->reorderRecordsTriggerAction(
fn (Action $action, bool $isReordering) => $action
->button()
->label($isReordering ? 'Disable reordering' : 'Enable reordering'),
);
}
Customizing the table header
You can add a heading to a table using the $table->heading()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->heading('Clients')
->columns([
// ...
]);
You can also add a description below the heading using the $table->description()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->heading('Clients')
->description('Manage your clients here.')
->columns([
// ...
]);
You can pass a view to the $table->header()
method to customize the entire header:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->header(view('tables.header', [
'heading' => 'Clients',
]))
->columns([
// ...
]);
Polling table content
You may poll table content so that it refreshes at a set interval, using the $table->poll()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->poll('10s');
}