F
Filament15mo ago
Jessy

change records per page in admin panel v2

protected function getTableRecordsPerPageSelectOptions(): array { return [10, 25, 50, 100]; } , this fn can be used in livewire component, how to do this in admin panel in v2?
4 Replies
ConnorHowell
ConnorHowell15mo ago
In the admin panel it needs to be on the page where the table is not the resource itself. Check you getPages method and you'll see the name of the class mapped to the 'index' route. In the below example you'll want to add that method to the ListRoles class:
public static function getPages(): array
{
return [
'index' => Pages\ListRoles::route('/'),
'create' => Pages\CreateRole::route('/create'),
'edit' => Pages\EditRole::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListRoles::route('/'),
'create' => Pages\CreateRole::route('/create'),
'edit' => Pages\EditRole::route('/{record}/edit'),
];
}
You'll edit it to look something along the lines of this:
class ListRoles extends ListRecords
{
protected static string $resource = RoleResource::class;

protected function getTableRecordsPerPageSelectOptions(): array
{
return [10, 25, 50, 100];
}

protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
class ListRoles extends ListRecords
{
protected static string $resource = RoleResource::class;

protected function getTableRecordsPerPageSelectOptions(): array
{
return [10, 25, 50, 100];
}

protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
ConnorHowell
ConnorHowell15mo ago
Resulting in:
No description
Jessy
JessyOP15mo ago
I have only Resource (noList, Create, Edit), so I put the fn in Manage and works. Ty
ConnorHowell
ConnorHowell15mo ago
No worries, yeah the ManageRecords page inherits the ListRecords page so same logic. Likewise, if you wanted to make use of a method that applies to a form; you would use that on either the manage class or the Edit/Create classes

Did you find this page helpful?