DataTableModel<T> constructor

DataTableModel<T>({
  1. required List<T> items,
  2. required List<Column> columns,
  3. required List<String> rowBuilder(
    1. T
    ),
  4. String title = '',
  5. String placeholder = 'Type to filter...',
  6. String noResultsText = 'No matching rows found',
  7. bool showTitle = true,
  8. bool showHelp = true,
  9. int pageSize = 10,
  10. DataTableStyles? styles,
})

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();
}