Table Pagination Modes
Pagination is enabled by default in Zonvoir Table.
You can control the pagination strategy, available page sizes, and default number of rows shown per page from your table class.
Configure pagination
Section titled “Configure pagination”Use the pagination properties on your table:
use Zonvoir\ZonvoirTable\Enums\PaginationType;
final class UsersTable extends Table{ protected PaginationType $paginationType = PaginationType::Standard;
protected ?array $perPageOptions = [ 15, 30, 50, 100, ];
protected ?int $defaultPerPage = 30;}This table will:
- Use standard Laravel pagination
- Show
30rows by default - Allow users to switch between
15,30,50, and100rows per page
Pagination types
Section titled “Pagination types”Zonvoir Table supports three Laravel pagination strategies.
| Type | Laravel method | Best for |
|---|---|---|
PaginationType::Standard |
paginate() |
Most tables that need page numbers and total counts |
PaginationType::Simple |
simplePaginate() |
Large datasets where total counts are unnecessary |
PaginationType::Cursor |
cursorPaginate() |
Large or frequently changing datasets |
Standard pagination
Section titled “Standard pagination”Standard pagination uses Laravel’s paginate() method.
protected PaginationType $paginationType = PaginationType::Standard;This is the default and is usually the best choice for general-purpose tables.
It provides information such as:
- Current page
- Last page
- Total records
- Previous and next pages
Example navigation:
Previous 1 2 3 4 5 NextSimple pagination
Section titled “Simple pagination”Use simple pagination when you only need previous and next navigation.
protected PaginationType $paginationType = PaginationType::Simple;This uses Laravel’s simplePaginate() method.
Because Laravel does not need to calculate the total number of records, simple pagination can be useful for larger datasets.
Example navigation:
Previous NextCursor pagination
Section titled “Cursor pagination”Use cursor pagination for large datasets where offset-based pagination may become expensive.
protected PaginationType $paginationType = PaginationType::Cursor;This uses Laravel’s cursorPaginate() method.
Instead of navigating using numeric page offsets, Laravel uses a cursor representing the current position in the result set.
Cursor pagination can be useful for:
- Large tables
- Frequently changing datasets
- Feeds or sequential navigation
- Queries where deep offset pagination becomes expensive
Cursor pagination works best when the query has a stable and deterministic ordering.
Rows per page
Section titled “Rows per page”Use $perPageOptions to control the values available in the rows-per-page selector.
protected ?array $perPageOptions = [ 10, 25, 50, 100,];Users can select one of these values from the table controls.
Default rows per page
Section titled “Default rows per page”Use $defaultPerPage to choose the initial page size.
protected ?int $defaultPerPage = 50;The default value should normally be included in $perPageOptions.
protected ?array $perPageOptions = [10, 25, 50, 100];
protected ?int $defaultPerPage = 50;Disable pagination
Section titled “Disable pagination”You can disable pagination entirely for a table.
final class UsersTable extends Table{ protected bool $pagination = false;}When pagination is disabled, the table returns the complete result set instead of a paginated result.
This is most appropriate for small datasets where loading every record at once is reasonable.
Pagination state
Section titled “Pagination state”The active page and rows-per-page value are stored in the table’s query string state.
For example:
?page=3&perPage=50With cursor pagination, the query string uses the active cursor instead of a numeric page.
When multiple named tables are rendered on the same page, pagination state remains isolated between them.
?users[page]=2&users[perPage]=30&jobs[page]=4Changing the users table will not affect the pagination state of the jobs table.
Example configuration
Section titled “Example configuration”A typical table might use:
use Zonvoir\ZonvoirTable\Enums\PaginationType;
final class UsersTable extends Table{ protected PaginationType $paginationType = PaginationType::Standard;
protected ?array $perPageOptions = [ 10, 25, 50, 100, ];
protected ?int $defaultPerPage = 25;}For a larger dataset, you might prefer:
final class ActivityTable extends Table{ protected PaginationType $paginationType = PaginationType::Cursor;
protected ?array $perPageOptions = [ 25, 50, 100, ];
protected ?int $defaultPerPage = 50;}