Skip to content

Sorting & pagination

Sorting and pagination are handled for you once a column opts in and a mode is chosen. The table sends the current sort and page to its endpoint, and the data source applies them.

TextColumn::make('name')->label('Name')->sortable();
NumberColumn::make('price')->label('Price')->sortable();
TextColumn::make('updated_at')->label('Updated')->dateTime()->sortable();

->sortable() adds the sort control to a column header. Clicking it cycles ascending, descending, and off, and the source applies an orderBy on the column key. Several columns can be sortable at once.

TextColumn::make('name')->sortable();

Sorting is keyed by the column key, so a sortable column must map to a real database column — or a to-one relation field, which sorts through a correlated subquery. Set a default order in the builder for when the user hasn’t chosen one.

Override pagination() to choose how rows are paged, and perPage() for the page size. The mode is a PaginationType:

ModeBehavior
PaginationType::TableFull pager with page numbers and total (the default).
PaginationType::SimplePrevious / next only — cheaper, no total count.
PaginationType::InfiniteLoads the next page as the user scrolls.
PaginationType::NoneReturns every row, no pagination.
use Lattice\Lattice\Tables\Enums\PaginationType;
public function pagination(): PaginationType
{
return PaginationType::Simple;
}
public function perPage(): int
{
return 50;
}

A custom data source chooses its own TableResult builder to match the mode — fromPaginator() for a full pager, fromSimplePaginator() for previous/next. The Eloquent source picks the right one from the mode automatically.