How to create custom list page?

Hi. I wanted to know how to create a custom list page.
6 Replies
Dan Harrin
Dan Harrin2y ago
Create a resource page as per the docs. Then use the table builder on it
Atena.D
Atena.DOP2y ago
Aren't resources just for CRUD? And also the table I want to create a list from, already has a resource but in this custom list I want to show it in two columns
Dan Harrin
Dan Harrin2y ago
resources are CRUD by default, but you can add multiple custom pages to them or, you can create a custom page outside of a resource and add the table builder to that
Atena.D
Atena.DOP2y ago
how can I do this? I mean in which method in a custom page should I specify the table builder
krekas
krekas2y ago
Read the docs
ahmant
ahmant2y ago
I really search in the Docs, but didn't find Can you please give me the link where I can find it in the doc? I found it, but reading the code, not the doc 1. Extend your custom page from ListRecords 2. Use this view
protected static string $view = 'filament::resources.pages.list-records';
protected static string $view = 'filament::resources.pages.list-records';
3. Add table function
protected function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('course')->formatStateUsing(fn (Course|null $state): string|null => $state?->name)->searchable()->hidden(request()->course > 0),
TextColumn::make('date_from')->searchable(),
TextColumn::make('date_to')->searchable(),
ToggleColumn::make('status'),
TextColumn::make('attachments')->formatStateUsing(fn (string $state): int => $state ? count(explode(',', $state)) : 0)->searchable(),
]);
->filters([
//
])
->actions([
Tables\Actions\EditAction::make()->authorize(fn (Session $record): bool => static::canEdit($record) || static::can('updateAttachments', $record)),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]);
}
protected function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('course')->formatStateUsing(fn (Course|null $state): string|null => $state?->name)->searchable()->hidden(request()->course > 0),
TextColumn::make('date_from')->searchable(),
TextColumn::make('date_to')->searchable(),
ToggleColumn::make('status'),
TextColumn::make('attachments')->formatStateUsing(fn (string $state): int => $state ? count(explode(',', $state)) : 0)->searchable(),
]);
->filters([
//
])
->actions([
Tables\Actions\EditAction::make()->authorize(fn (Session $record): bool => static::canEdit($record) || static::can('updateAttachments', $record)),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]);
}
4. Add getTableQuery function
protected function getTableQuery(): Builder
{
return static::getResource()::getModel()::query();
}
protected function getTableQuery(): Builder
{
return static::getResource()::getModel()::query();
}
Want results from more Discord servers?
Add your server