When range selection happened, I can listen to rangeSelectionChanged
event. Is there any event I can listen to when all selected range are cleared?
ag-grid: is there a way to trigger event when clear range selection
1.6k Views Asked by jason135 At
2
There are 2 best solutions below
0

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 ifGridApi.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();
}
}}
{...}
/>
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