Blog / Laravel / Filament

Filament: Custom pagination in Resources Table

Hey there, folks! Today, I'm excited to share a cool little trick that'll help you customize the paginator inside a Resource in the Filament package for Laravel. It's super easy, so let's dive right in!

So, you know how the default Resource comes with a pagination of just 10 records per page? And sure, you can choose from 25, 50, or even view all the records. But let's face it, sometimes 10 is just way too few, right? We want to show more entries per page, and I got you covered!

Now, here's the thing. The documentation does give an example for adding a table as a component to the page, but it totally skips explaining what to do with the Resource. And guess what? It's not just you; other folks on GitHub have had the same question but found no clear answers. But fear not, I'm here to shed some light on your projects!

So, let's get started. For this example, let's assume we're going to make some changes to the UserResource. Inside your resource folder, you'll find the precious gem we need – the ListUsers.php file.

app/
├─ Filament/
│  ├─ Resources/
│  │  ├─ UserResource/
│  │  │  ├─ Pages
│  │  │  │  ├─ CreateUser.php
│  │  │  │  ├─ EditUser.php
│  │  │  │  ├─ ListUsers.php ← this is the file

Easy peasy! Now, to make this pagination customization happen, all you gotta do is add the following function to your ListUsers.php file.

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

That's it! You've got the power to customize your paginator like a pro. Feel free to experiment with different values and find what works best for your system. Happy coding! 🚀