onGridSelectionModeChanged method
Called when the SfDataGrid.selectionMode is changed at run time.
Implementation
@override
void onGridSelectionModeChanged() {
final DataGridConfiguration dataGridConfiguration =
_dataGridStateDetails!();
if (dataGridConfiguration.selectionMode == SelectionMode.none) {
dataGridConfiguration.headerCheckboxState = false;
_clearSelectedRows(dataGridConfiguration);
_pressedRowColumnIndex = RowColumnIndex(-1, -1);
} else if (dataGridConfiguration.selectionMode != SelectionMode.none &&
dataGridConfiguration.selectionMode != SelectionMode.multiple) {
DataGridRow? lastRecord = dataGridConfiguration.controller.selectedRow;
_clearSelection(dataGridConfiguration);
if (dataGridConfiguration.navigationMode == GridNavigationMode.cell &&
lastRecord != null) {
final RowColumnIndex currentRowColumnIndex =
_getRowColumnIndexOnModeChanged(dataGridConfiguration, lastRecord);
if (currentRowColumnIndex.rowIndex <= 0) {
return;
}
lastRecord = dataGridConfiguration.selectionMode == SelectionMode.single
? selection_helper.getRecord(
dataGridConfiguration,
grid_helper.resolveToRecordIndex(
dataGridConfiguration, currentRowColumnIndex.rowIndex))
: lastRecord;
dataGridConfiguration.currentCell._moveCurrentCellTo(
dataGridConfiguration,
RowColumnIndex(currentRowColumnIndex.rowIndex,
currentRowColumnIndex.columnIndex),
isSelectionChanged: true);
}
if (lastRecord != null) {
_addSelection(lastRecord, dataGridConfiguration);
}
} else if (dataGridConfiguration.isDesktop &&
dataGridConfiguration.selectionMode == SelectionMode.multiple) {
final RowColumnIndex currentRowColumnIndex =
RowColumnIndex(dataGridConfiguration.currentCell.rowIndex, -1);
dataGridConfiguration.currentCell._updateBorderForMultipleSelection(
dataGridConfiguration,
nextRowColumnIndex: currentRowColumnIndex);
}
}