F
Filament10mo ago
ericmp

Issue Paginating Multiple Tables in Admin Dashboard

I'm utilizing two widgets in the Filament dashboard, which happen to be two tables. However, when I paginate one of them, the URL simply displays "/admin?page=n" without specifying the table's identity. Despite implementing queryStringIdentifier for both tables, I'm unable to discern which table's page is being displayed. Is there a crucial step I'm overlooking? 🤔 on table 1:
->queryStringIdentifier('top_listened_songs')
->queryStringIdentifier('top_listened_songs')
on table 2:
->queryStringIdentifier('top_listened_artists')
->queryStringIdentifier('top_listened_artists')
Solution:
try to use this method in the widget ```php protected function paginateTableQuery(\Illuminate\Database\Eloquent\Builder $query): \Illuminate\Contracts\Pagination\Paginator {...
Jump to solution
14 Replies
ericmp
ericmpOP10mo ago
anyone ^^
Solution
LeandroFerreira
LeandroFerreira10mo ago
try to use this method in the widget
protected function paginateTableQuery(\Illuminate\Database\Eloquent\Builder $query): \Illuminate\Contracts\Pagination\Paginator
{
$perPage = $this->getTableRecordsPerPage();

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

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

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

return $records->onEachSide(0);
}
ericmp
ericmpOP10mo ago
awesome thanks a lot 🙏
LeandroFerreira
LeandroFerreira10mo ago
Sorry, remove this code and use this trait
use Filament\Tables\Concerns\CanPaginateRecords;
use Filament\Tables\Concerns\CanPaginateRecords;
this will override the simple pagination
ericmp
ericmpOP10mo ago
ohh cool is this in the docs? i think we should add it
LeandroFerreira
LeandroFerreira10mo ago
no
ericmp
ericmpOP10mo ago
no, for the 1st question i guess u mean
LeandroFerreira
LeandroFerreira10mo ago
this isn't in the docs I guess
Dushmanta
Dushmanta9mo ago
@Leandro Ferreira Hi!! I'm also using two widget table on a single page, but I'm facing an issue, Let me describe the issue Let's say I've 2 tables Payments and Anonymous payments now Payments has 20 records and Anonymous payment has 4 records and each table shows 10 data by default, now when I go the next page of pagination in Payments table, it shows the data of 10-20 but if I refresh the page the same 10-20 data of Payments shows but the Anonymous table shows null data because in the URL it shows page=2 (e.g. http://127.0.0.1:8000/admin/event/payments?page=2) and no pagination shows to get back to the 4 Anonymous payment data. So Could you please tell if I can move through pagination without changing the URL, that would resolve it I guess? Could you please help, thank you for your valuable time 🙂
Dushmanta
Dushmanta9mo ago
Thank you for your response 🙂
use Filament\Tables\Table;

public function table(Table $table): Table
{
return $table
->queryStringIdentifier('users');
}
use Filament\Tables\Table;

public function table(Table $table): Table
{
return $table
->queryStringIdentifier('users');
}
Here, I presume "users" is the resource model, Both of my widgets are from same resource and my issue remains same even after using the queryStringIdentifier, Could you please confirm if it's the model or not?
LeandroFerreira
LeandroFerreira9mo ago
No it is an identifier that you can use different values to each widget tables
Dushmanta
Dushmanta9mo ago
Here as you can see I've used 2 different identifiers for each table but when I refresh the page same issue occurs, please refer to the video, thank you
No description
No description
Dushmanta
Dushmanta9mo ago
Hi! It's working after overriding the paginateTableQuery() function.
Want results from more Discord servers?
Add your server