When range selection happened, I can listen to rangeSelectionChanged event. Is there any event I can listen to when all selected range are cleared?
When range selection happened, I can listen to rangeSelectionChanged event. Is there any event I can listen to when all selected range are cleared?
If I understood correctly by selected range are cleared I am assuming user is randomly clicking on any cell in the grid thus only one cell is getting highligheted and range is cleared. for this there is no separate event so you have to check the CellRange object in that case.
below logic you can use inside rangeSelectionChanged event
onRangeSelectionChanged(event) {
...
...
//lets check here if selection is cleared by user or not
var cellRanges = this.gridApi.getCellRanges(); // this gives the cellrange object.
var startRowIndex = cellRanges[0].startRow.rowIndex;
var endRowIndex = cellRanges[0].endRow.rowIndex;
var NumberOfColumns = cellRanges[0].columns.length;
//cellRange.length shows how many different ranges user has selected in Grid
if(startRowIndex === endRowIndex && NumberOfColumns ===1 && cellRanges.length<2)
{
//do your processing here
}
You can use either:
onSelectionChanged to detect if the user clear range selection by clicking a cell (single cell selection)onRangeSelectionChanged to detect if the user clear range selection completely by checking if GridApi.getCellRanges().length === 0 inside the callback<AgGridReact
enableRangeSelection
onSelectionChanged={(e) => {
onSingleSelection();
}}
onRangeSelectionChanged={(e) => {
const cellRanges = e.api.getCellRanges();
const rangeSelectionCount = cellRanges.length;
if (rangeSelectionCount === 0) {
onClearSelection();
}
}}
{...}
/>