Is there any grid api to deselect ag-grid selected rows programatically? I'm trying to perform some operation on the selected row, basically an async operation , after which I need to deselect this row from the grid .
rowDeselection : Set to true or false . If true, then rows will be deselected if you hold down ctrl + click the row. Normal behaviour with the grid disallows deselection of nodes (ie once a node is selected, it remains selected until another row is selected in its place).
There is no option in the library to make a single row disabled(both visually and keyboard event based), the only way we could make a single row disabled is by using a customCellRenderer for both header and subsequent cell checkboxes, this allows full control over the checkbox.
suppressCellSelection = true we can disable cell selection for all columns' cells. Here the question is regarding not showing a specific column's cell's highlighted border when it is selected. You can achieve this by bit of CSS and cellClass property of ColDef .
Select a row by clicking on it. Selecting a row will remove any previous selection unless you hold down Ctrl while clicking. Selecting a row and holding down Shift while clicking a second row will select the range. Remember Row Selection works with all frameworks (e.g. Angular and React) as well as plain JavaScript.
I believe it is weird but setting rowDeselection
to true
didn't work for me. What I wanted was simple: Being able to deselect a row when it was selected already. So I checked the Row Selection section of AG Grid's documentation and I find this:
rowMultiSelectWithClick: ... Clicking a selected row in this mode will deselect the row.
Huh! Yeah that sounds like what I need! But I don't want multiple selection...! I want single selection ONLY. So I thought maybe setting rowSelection
to single
will fix it and the selection will be single and deselectable. And... yes it works! The reason I was in doubt initially when doing this is using "rowMultiSelectWithClick" together with "single rowSelection" sounds contradictory, but it works anyways and this is the thing that matters really! :)
So e.g., if you're using it in React (quite similar in Angular or Vanilla JavaScript), just add:
<AgGridReact
rowSelection="single"
rowMultiSelectWithClick={true}
//...
>
Used grip api deselectAll function . It worked !
this.gridOptions.api.deselectAll();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With