apply<TRow extends DataGridRow> method

  1. @override
Future<DataGridState<TRow>?> apply<TRow extends DataGridRow>(
  1. EventContext<TRow> context
)
override

Apply this event's transformation to the state. Returns the new state, or null if no state change should occur. Can return a Future for async operations.

Implementation

@override
Future<DataGridState<TRow>?> apply<TRow extends DataGridRow>(EventContext<TRow> context) async {
  final rowsMap = {for (var row in rows) (row as TRow).id: row as TRow};
  final newRowsById = append ? {...context.state.rowsById, ...rowsMap} : rowsMap;

  context.dataIndexer.setData(newRowsById);

  final filteredIds = context.state.filter.hasFilters
      ? await context.filterDelegate.applyFilters(
          rowsById: newRowsById,
          filters: context.state.filter.columnFilters.values.toList(),
          columns: context.state.columns,
        )
      : newRowsById.keys.toList();

  final sortedIds = context.state.sort.hasSort
      ? context.dataIndexer.sortIds(newRowsById, filteredIds, context.state.sort.sortColumn!, context.state.columns)
      : filteredIds;

  return context.state.copyWith(rowsById: newRowsById, displayOrder: sortedIds, isLoading: false);
}