Pagination applies to multiple table after page refresh

Hello! I'm using 2 widget tables (let's say Table 1 and Table 2) on a single page, and they have pagination. Now, when I paginate to another page (let's say to page 2) in Table 1 and refresh the page, Table 2 also gets paginated to page 2. The issue becomes more relevant when Table 2 has less data because on the 2nd page of Table 2, it shows no data and the pagination buttons are disabled. Can anyone help me with this issue? Thank you for your valuable time. I really appreciate it.
2 Replies
Dushmanta
DushmantaOP9mo ago
I was able to solve the issue by using - queryStringIdentifier('string') (https://filamentphp.com/docs/3.x/tables/advanced#preventing-query-string-conflicts-with-the-pagination-page) - Overriding the paginateTableQuery() function inside the widget
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
in
protected function paginateTableQuery(Builder $query): Paginator|CursorPaginator
{
$perPage = $this->getTableRecordsPerPage();

/** @var LengthAwarePaginator $records */
$records = $query->paginate(
$perPage === 'all' ? $query->count() : $perPage,
['*'],
$this->getTablePaginationPageName(),
);

return $records->onEachSide(0);
}
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
in
protected function paginateTableQuery(Builder $query): Paginator|CursorPaginator
{
$perPage = $this->getTableRecordsPerPage();

/** @var LengthAwarePaginator $records */
$records = $query->paginate(
$perPage === 'all' ? $query->count() : $perPage,
['*'],
$this->getTablePaginationPageName(),
);

return $records->onEachSide(0);
}
Dushmanta
DushmantaOP9mo ago
Although I wanted to implement this feature with Simple pagination, which didn't work, if anyone finds this, please do comment. Thank you.
Want results from more Discord servers?
Add your server