Navigation

Pagination

Previous, numbered pages around the current one, and next. Links or buttons.

JxPagination import 'package:jx_cli/ui.dart' Available since 0.0.2

Preview

When to use it

  • Long lists and tables.
  • Search results.

States

First page
Few pages

Minimal example

Dart
JxPagination(page: page, pageCount: 12, href: (p) => '/invoices?page=$p')

Complete example

A full Jaspr component you can paste into a project.

Dart
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';

/// Server-rendered list: plain links, works without JavaScript.
class ResultsPager extends StatelessComponent {
  const ResultsPager({required this.page, required this.total, super.key});

  final int page;
  final int total;

  @override
  Component build(BuildContext context) {
    return JxPagination(
      page: page,
      pageCount: (total / 20).ceil(),
      label: 'Search results pages',
      href: (p) => '/search?page=$p',
    );
  }
}

Properties

Property Type Default Description
page int required Current page, from 1.
pageCount int required Number of pages.
href String Function(int)? null Builds the link of a page: renders links.
label String 'Pagination' Accessible name of the <nav> .
previousLabel String 'Previous' Text of the previous link.
nextLabel String 'Next' Text of the next link.
classes String? null Extra JX classes, appended after the component classes.

Related types

Name Role
JxPagination.visiblePages(page, pageCount) Static helper: pages to show, with null for gaps.

Events

Callback Type Fires when
onChange ValueChanged<int>? A page button is clicked (when href is null): gives the page number.

Customizing

  • Pass classes to add or override utilities: they come last, so classes: 'w:full' wins over the default width.

Responsive

  • Items wrap on narrow screens; at most 7 entries plus previous and next.

Accessibility

  • A <nav> landmark; the current page carries aria-current="page".
  • At the ends, previous or next is disabled (aria-disabled, removed from the tab order for links).
  • Gaps (…) are hidden from screen readers.