Table Widget - extremePaginationLinks and queryStringIdentifier not working

As per screenshots - I've tried setting the queryStringIdentifier and extremePaginationLinks on a table widget but it doesn't seem to work. I'm still getting ?page=2 in the URL and no extra pagination links 😢 Is this a bug or am I maybe expecting too much of the widgets? If anyone has any tips on how I could get this working I'd be very grateful.
<?php

namespace App\Filament\Widgets;

use App\Enums\DashboardGroup;
use App\Models\WidgetCacheRevenue;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;

class DailyRevenue extends BaseWidget
{
protected int | string | array $columnSpan = 'full';

public function table(Table $table): Table
{
return $table
->query(WidgetCacheRevenue::query())
->columns([
TextColumn::make('created_at')
->date('jS M Y')
->label('Date'),
TextColumn::make('impressions')
->numeric(),
TextColumn::make('revenue_raw')
->numeric(decimalPlaces: 2)
->label('Earnings'),
TextColumn::make('viewability')
->label('Viewability')
->numeric(decimalPlaces: 2)
->suffix('%'),
])

// These two functions don't appear to do anything on a widget?
->queryStringIdentifier('daily-revenue')
->extremePaginationLinks();
}
}
<?php

namespace App\Filament\Widgets;

use App\Enums\DashboardGroup;
use App\Models\WidgetCacheRevenue;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;

class DailyRevenue extends BaseWidget
{
protected int | string | array $columnSpan = 'full';

public function table(Table $table): Table
{
return $table
->query(WidgetCacheRevenue::query())
->columns([
TextColumn::make('created_at')
->date('jS M Y')
->label('Date'),
TextColumn::make('impressions')
->numeric(),
TextColumn::make('revenue_raw')
->numeric(decimalPlaces: 2)
->label('Earnings'),
TextColumn::make('viewability')
->label('Viewability')
->numeric(decimalPlaces: 2)
->suffix('%'),
])

// These two functions don't appear to do anything on a widget?
->queryStringIdentifier('daily-revenue')
->extremePaginationLinks();
}
}
No description
No description
2 Replies
trymedo
trymedoOP6mo ago
Updated post as I didn't realise screenshots of code were not allowed, apologies. I've tested the queryStringIdentifier on another page and it works fine. It feels both of these issues (query string and normal pagination) is only an issue for Widgets. I can work around this for now but does anyone know if there's a plan to get custom pagination queries on widgets in future? I would happily work on a PR for it myself but I'm still fairly new to Filament and don't really know where to begin.
Benjamin
Benjamin6mo ago
Same problem here (https://discord.com/channels/883083792112300104/1260230838516187167) but I didn't found a solution yet. I found a solution. Make a custom BaseTableWidget and override the paginateTableQuery() by copying the base method from the Filament\Tables\Concerns\CanPaginateRecords trait :
<?php

declare(strict_types=1);

namespace App\Filament\Widgets;

use Filament\Widgets\TableWidget;
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\App;

abstract class NanouBaseTableWidget extends TableWidget
{
protected function paginateTableQuery(Builder $query): Paginator | CursorPaginator
{

$perPage = $this->getTableRecordsPerPage();

if (version_compare(App::version(), '11.0', '>=')) {
$total = $query->toBase()->getCountForPagination();

/** @var LengthAwarePaginator $records */
$records = $query->paginate(
perPage: ($perPage === 'all') ? $total : $perPage,
columns: ['*'],
pageName: $this->getTablePaginationPageName(),
total: $total,
);
} else {
/** @var LengthAwarePaginator $records */
$records = $query->paginate(
perPage: ($perPage === 'all') ? $query->toBase()->getCountForPagination() : $perPage,
columns: ['*'],
pageName: $this->getTablePaginationPageName(),
);
}

return $records->onEachSide(0);
}
}
<?php

declare(strict_types=1);

namespace App\Filament\Widgets;

use Filament\Widgets\TableWidget;
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\App;

abstract class NanouBaseTableWidget extends TableWidget
{
protected function paginateTableQuery(Builder $query): Paginator | CursorPaginator
{

$perPage = $this->getTableRecordsPerPage();

if (version_compare(App::version(), '11.0', '>=')) {
$total = $query->toBase()->getCountForPagination();

/** @var LengthAwarePaginator $records */
$records = $query->paginate(
perPage: ($perPage === 'all') ? $total : $perPage,
columns: ['*'],
pageName: $this->getTablePaginationPageName(),
total: $total,
);
} else {
/** @var LengthAwarePaginator $records */
$records = $query->paginate(
perPage: ($perPage === 'all') ? $query->toBase()->getCountForPagination() : $perPage,
columns: ['*'],
pageName: $this->getTablePaginationPageName(),
);
}

return $records->onEachSide(0);
}
}
Then, in your widget extends it, add ->extremePaginationLinks() to your table and be sure the widget is large enough to allow the pagination to be displayed.
Want results from more Discord servers?
Add your server