DataTableModel<T> constructor
DataTableModel<T> ({})
Implementation
DataTableModel({
required List<T> items,
required List<Column> columns,
required List<String> Function(T) rowBuilder,
this.title = '',
this.placeholder = 'Type to filter...',
this.noResultsText = 'No matching rows found',
this.showTitle = true,
this.showHelp = true,
int pageSize = 10,
DataTableStyles? styles,
}) : _items = items,
_rowBuilder = rowBuilder,
styles = styles ?? DataTableStyles() {
_input = TextInputModel(prompt: '🔍 ', placeholder: placeholder);
// Compute total table width from columns (each column has 2 chars padding
// from TableStyles.cell default which adds padding(0, 1) = left+right).
final totalWidth = columns.fold(0, (sum, c) => sum + c.width + 2);
_table = TableModel(
columns: columns,
rows: [],
height: pageSize + 2, // +1 for header, +1 to account for setHeight offset
styles: TableStyles(
header: this.styles.tableHeader,
cell: this.styles.tableCell,
selected: this.styles.tableSelected,
),
)..focus();
// Width MUST be set after construction so viewport gets a non-zero width.
_table.setWidth(totalWidth);
_paginator = PaginatorModel(
perPage: pageSize,
type: PaginationType.dots,
activeDot: '●',
inactiveDot: '○',
);
_runFilter();
}