onCellSubmit method

  1. @nonVirtual
  2. @override
Future<void> onCellSubmit(
  1. DataGridRow dataGridRow,
  2. RowColumnIndex rowColumnIndex,
  3. GridColumn column
)

Called whenever the cell’s editing is completed.

Typically, this will be called whenever the notifyListeners is called when cell is in editing mode and key navigation is performed to move a cell to another cell from the cell which is currently editing. For eg, Enter key, TAB key and so on.

The following example show how to override this method and save the currently edited value for specific column.

@override
void onCellSubmit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
    GridColumn column) {
  final dynamic oldValue = dataGridRow
      .getCells()
      .firstWhereOrNull((DataGridCell dataGridCell) =>
  dataGridCell.columnName == column.columnName)
      ?.value ??
      '';

  final int dataRowIndex = rows.indexOf(dataGridRow);

  if (newCellValue == null || oldValue == newCellValue) {
    return;
  }

  if (column.columnName == 'id') {
    rows[dataRowIndex].getCells()[rowColumnIndex.columnIndex] =
        DataGridCell<int>(columnName: 'id', value: newCellValue);

    // Save the new cell value to model collection also.
    employees[dataRowIndex].id = newCellValue as int;
  }

  // To reset the new cell value after successfully updated to DataGridRow
  //and underlying mode.
  newCellValue = null;
}

This method will never be called when you return false from onCellBeginEdit.

Implementation

@nonVirtual
@override
Future<void> onCellSubmit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex, GridColumn column) {
  return xOnCellSubmit(dataGridRow as XDataGridRow, rowColumnIndex, column);
}