Skip to content

Data Tables — vyuh_table

vyuh_table is the CDX data-table package. It composes CDX UI tokens and controls, but it is imported directly rather than re-exported by vyuh_cdx_ui.

dart
import 'package:vyuh_table/vyuh_table.dart';

Live Example

Open the full route: Data Table.

TableWidget

Table widget compositionColumns, items, optional config, callbacks, and state builders feed TableWidget. The table emits row, page, column order, and resize events to the host.TableColumn<T>items + stateTableWidgetresize, reorder, pin,page, expandHost callbacksrow tap, page, resize,column order

TableWidget<T> renders generic tabular data with column resizing, column reordering, pinned leading columns, row selection, expansion rows, loading / error / empty states, and optional pagination.

dart
TableWidget<Area>(
  columns: [
    TableColumn.text(
      field: 'name',
      label: 'Name',
      getValue: (area) => area.name,
      widthFactor: 0.30,
      minWidth: 220,
    ),
    TableColumn.badge(
      field: 'status',
      label: 'Status',
      getValue: (area) => area.statusLabel,
      getColor: (area) => area.statusColor,
      widthFactor: 160,
    ),
    TableColumn.number(
      field: 'capacity',
      label: 'Capacity',
      getValue: (area) => area.capacity,
      suffix: ' units',
      widthFactor: 140,
    ),
  ],
  items: pageItems,
  totalCount: totalCount,
  currentPage: page,
  pageSize: pageSize,
  enablePagination: true,
  onPageChanged: (nextPage) => setState(() => page = nextPage),
  onPageSizeChanged: (nextSize) => setState(() => pageSize = nextSize),
  selectedItem: selectedArea,
  onRowTap: (area) => context.go('/areas/${area.id}'),
)

Column Model

TableColumn<T> is intentionally generic and has no entity-system dependency. Width is expressed through widthFactor:

  • 0 < widthFactor < 1 means a fraction of the available table width.
  • widthFactor >= 1 means a fixed logical-pixel width.
  • null means no declared width; the column relies on minWidth.

Factories:

FactoryUse
TableColumn.textSimple text cells with maxLines and ellipsis
TableColumn.badgeInline colored badge cells with optional icon
TableColumn.numberNumeric cells with optional prefix / suffix
TableColumn.customFull custom cell builder plus optional custom header

Header extension points include headerBuilder, onHeaderTap, headerActionsBuilder, and menuItemsBuilder.

Column Menus

ColumnMenuItem is a sealed model rendered by the table header chrome:

TypeUse
ColumnMenuActionTappable row with optional icon
ColumnMenuSubmenuNested menu section
ColumnMenuCheckboxToggleable menu item
ColumnMenuDividerVisual divider

Behavior And State

Key TableWidget behavior flags:

ParamDefaultPurpose
enableColumnResizetrueDrag column edges to resize
enableColumnReordertrueDrag headers to reorder
showCellBorderstrueVertical cell borders
enablePaginationfalseRender pagination bar and slice rows
showRowNumbersfalseAdd global row-number column
pinnedColumnCount0Freeze leading data columns during horizontal scroll
expansionBuildernullEnables expandable rows

When enablePagination is true and onPageChanged is provided, the caller owns pagination and supplies the current page's items. Without onPageChanged, the widget can self-manage pagination from the full items list.

API Parameters

TypeParameterPurpose
TableWidgetcolumns, itemsRequired column model and rows to display.
TableWidgetcurrentPage, pageSize, totalCountControlled pagination state when onPageChanged is set.
TableWidgetenablePaginationShows pagination and slices rows in self-managed mode.
TableWidgetonColumnReordered, onColumnResizedPersist saved-view order and width changes.
TableWidgetpinnedColumnCount, showRowNumbersFreeze leading data columns and optionally add global row numbers.
TableWidgetexpansionBuilder, expansionMaxHeightEnable expandable row details.
TableColumnwidthFactor, minWidthFractional/fixed width and per-column floor.
TableColumnheaderActionsBuilder, menuItemsBuilderHeader action slots and column context menu items.
TableConfigtheme, density, state buildersReusable visual/behavior bundle for table families.

TableConfig, Density, Theme

Use TableConfig when a table type has stable visual and behavior settings:

dart
const tableConfig = TableConfig(
  rowHeight: 56,
  pinnedColumnCount: 1,
  enablePagination: true,
  showRowNumbers: true,
  density: TableDensity.normal,
);

TableWidget<Area>(
  config: tableConfig,
  columns: columns,
  items: areas,
)

TableDensity values are compact, normal, and relaxed. Passing density derives a TableTheme from the ambient ThemeData and CdxConfig; passing theme gives full visual override control.

Resize Infrastructure

HoverColumnResizer and TableResizeStore are public so custom table headers can share the same resize behavior and state model as TableWidget.

  • Theming — table theme derives from CdxConfig
  • Buttons — header actions reuse CDX buttons
  • Field Formatting — format values before rendering custom cells