How to improve table pagination performance

Trick Tables Integration
Dan Harrin avatar Author: Dan Harrin
Published: Aug 01, 2023

You may use the hammerstone/fast-paginate package. The theory for this feature can be found here.

You need to override the paginateTableQuery method. This should be on your Livewire component class. If you're using a panel resource, the Livewire component is your List or Manage page (in the /Pages directory of the resource). If you're using a panel relation manager, this class is the Livewire component.

use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
 
protected function paginateTableQuery(Builder $query): Paginator
{
    return $query->fastPaginate(($this->getTableRecordsPerPage() === 'all') ? $query->count() : $this->getTableRecordsPerPage());
}

The author

Dan Harrin avatar Author: Dan Harrin

Dan is a software engineer from the UK. He is one of the co-creators of Filament, and leads development of the project. He is passionate about open-source software, and building tools that simplify complex problems.

When he's not coding, Dan enjoys music, board games, and cooking.

Articles
11

From the same author