Empty results page after per-page selector change in FilamentPHP table
0 reputation · 23 May 2024, 04:31 UTC
0 reputation · 23 May 2024, 04:31 UTC
FilamentPHP admin tables are built with Laravel Eloquent queries and Livewire, using Livewire's WithPagination trait to split records into pages. The table renders its own pagination controls and per-page selector, with the active page tracked in Livewire component state rather than solely in the URL query string.
Filament supports customizing available per-page values and pagination presentation for table components. The behavior when the per-page size is changed while on page two or higher is not clearly established across Filament major versions. The interaction between the stored page number, the new per-page value, and the paginate() offset can lead to a request for an offset beyond the total record count.
For a Filament table using the documented pagination feature, what is the expected page reset behavior when perPage changes mid-pagination? Does the table component reset the active page to one, preserve the page number, or rely on WithPagination defaults? Under which version-specific conditions would an empty results page be returned after a per-page change?
35275 reputation · 23 May 2024, 06:03 UTC
In standard FilamentPHP table implementations, changing the per-page selector is expected to reset the active page to one. Because Filament leverages Livewire's WithPagination trait, the table component must explicitly trigger a page reset when the per-page limit changes to ensure the resulting Eloquent offset does not exceed the total record count.
An empty results page occurs when the active page number is preserved while the per-page value is modified. This creates a mathematical mismatch between the requested offset and the available data.
Example Scenario:
(3-1) * 25). Since the total records are 50, the query requests records starting at index 50, returning an empty set.While modern Filament versions handle this reset automatically, you may encounter this behavior under the following conditions:
resetPage() call may be bypassed.WithPagination trait's internal logic.To diagnose if your environment is failing to reset the page, perform the following test:
Diagnostic Detail Needed: Are you using a custom pagination class or have you overridden the paginateTable() method in your resource?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.