onChangeHandler method

Future<bool> onChangeHandler(
  1. int rowIdx,
  2. int colIdx,
  3. dynamic value,
  4. dynamic oldValue,
)

Implementation

Future<bool> onChangeHandler(
    int rowIdx,
    int colIdx,
    dynamic value,
    dynamic oldValue) async {

  var row = (rowIdx >= 0 && rowIdx < rows.length) ? rows[rowIdx] : null;
  var rowCell = row?.cell(colIdx);
  var colCell = header?.cell(colIdx);
  var data = getData(rowIdx);
  var fld = colCell?.field;

  bool ok = true;
  if (data != null && colCell != null && fld != null) {

    // mark dirty
    row?.dirty = true;
    rowCell?.dirty = true;
    //rowCell?.touched = true;

    // write new value
    // the data needs to be written ahead of alarm validation
    // in order for binding to work correctly
    Data.write(data, fld, value);

    // set current data
    row?.data = data;

    // set selected to current data
    selected = data;

    // validation alarm?
    ok = !(rowCell?.alarming ?? false);
    if (!ok) rowCell?.onAlarm();

    // fire the row's cell change handler
    if (ok) ok = await rowCell?.onChangeHandler() ?? true;

    // fire the row's change handler
    if (ok) ok = await row?.onChangeHandler() ?? true;

    // fire the column's cell change handler
    if (ok) ok = await colCell.onChangeHandler();

    // fire the column's change handler
    if (ok) ok = await header?.onChangeHandler() ?? true;

    // fire the table's change handler
    if (ok) {
      ok = _onChange != null
          ? await EventHandler(this).execute(_onChange)
          : true;
    }

    // on fail, restore old value
    if (!ok) {

      // write back old value
      Data.write(data, fld, oldValue);

      // reset current row data
      row?.data = data;

      // reset selected
      selected = data;
    }
  }
  return ok;
}