Data display

Data table

A table with a caption, sortable headers, numeric columns, striped rows, a sticky header and an empty state. You own the data: it reports clicks on headers.

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

Preview

Invoices
Stark Paid $7,250 2026-08-30
Cyberdyne Paid $5,120 2026-10-15
Hooli Pending $3,990 2026-12-01
Tyrell Pending $2,875 2026-11-29
Initech Pending $2,310 2026-11-20
Showing 1–5 of 12

When to use it

  • Invoices, users, orders.
  • Any list compared column by column.

States

Client Amount
No invoice this month
Empty
Key Value
Region Europe
Plan Pro
Dense, no stripes

Minimal example

Dart
JxDataTable(
  columns: const [JxColumn('Client'), JxColumn('Amount', numeric: true)],
  rows: [
    [.text('Acme'), .text('$1,240')],
    [.text('Globex'), .text('$860')],
  ],
)

Complete example

A full Jaspr component you can paste into a project.

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

typedef Invoice = ({String client, int amount});

/// Sortable invoices, five per page.
class Invoices extends StatefulComponent {
  const Invoices(this.invoices, {super.key});

  final List<Invoice> invoices;

  @override
  State<Invoices> createState() => _InvoicesState();
}

class _InvoicesState extends State<Invoices> {
  static const pageSize = 5;
  int sortColumn = 1;
  bool ascending = false;
  int page = 1;

  @override
  Component build(BuildContext context) {
    final rows = [...component.invoices]
      ..sort((a, b) {
        final order = sortColumn == 0 ? a.client.compareTo(b.client) : a.amount.compareTo(b.amount);
        return ascending ? order : -order;
      });
    final pageCount = (rows.length / pageSize).ceil();
    return div([
      JxDataTable(
        caption: 'Invoices',
        stickyHeader: true,
        columns: const [
          JxColumn('Client', sortable: true),
          JxColumn('Amount', numeric: true, sortable: true),
        ],
        sortColumn: sortColumn,
        sortAscending: ascending,
        onSort: (column) => setState(() {
          ascending = column == sortColumn ? !ascending : true;
          sortColumn = column;
          page = 1;
        }),
        rows: [
          for (final invoice in rows.skip((page - 1) * pageSize).take(pageSize))
            [.text(invoice.client), .text('\$${invoice.amount}')],
        ],
      ),
      JxPagination(page: page, pageCount: pageCount, onChange: (p) => setState(() => page = p)),
    ]);
  }
}

Properties

Property Type Default Description
columns List<JxColumn> required Headers, in order.
rows List<List<Component>> required One list of cells per row: text, badges, buttons…
caption String? null Title of the table, read first by screen readers.
striped bool true Alternating row background.
hover bool true Highlights the row under the pointer.
dense bool false Smaller cell padding.
stickyHeader bool false Header stays visible while the table scrolls (max height 28rem).
sortColumn int? null Index of the sorted column ( aria-sort ).
sortAscending bool true Direction of the sort.
emptyText String 'No data' Shown in a single row when rows is empty.
classes String? null Extra JX classes, appended after the component classes.

Related types

Name Role
JxColumn(label, numeric: false, sortable: false) A column: numeric aligns right with tabular digits.

Events

Callback Type Fires when
onSort ValueChanged<int>? A sortable header is clicked; gives the column index. Without it, headers are plain text.

Customizing

  • Pass classes to add or override utilities: they come last, so classes: 'w:full' wins over the default width.
  • Cells take any component: put a JxBadge or a JxButton in a row.

Responsive

  • On narrow screens the table scrolls sideways inside its frame, never the page. Cells do not wrap.

Accessibility

  • A real <table> with <caption> and <th scope="col">.
  • Sortable headers are buttons inside the <th>, which carries aria-sort="ascending" or "descending".
  • The sort arrow is decorative; the direction is exposed by aria-sort.

Limitations

  • Sorting, filtering and paging are yours: the table renders what you give it.
  • No row selection and no column resizing.