Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deselect selected rows from ag grid angular

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 .

like image 426
Riya Avatar asked Sep 06 '18 08:09

Riya


People also ask

How do I deselect all selected rows in Ag 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).

How do I turn off the particular row in Ag grid?

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.

How do you turn off cell selection on Ag grid?

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 .

Is row selectable in Ag grid?

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.


2 Answers

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}
    //...
>
like image 74
aderchox Avatar answered Oct 03 '22 00:10

aderchox


Used grip api deselectAll function . It worked !

this.gridOptions.api.deselectAll();
like image 30
Riya Avatar answered Oct 03 '22 01:10

Riya