2

Is there a way in ag-grid that after selecting the row with the help of checkbox selection and also selecting a row with the help of another cell click selection in such a way that after selecting the rows on cell click event, the previously selected rows remains selected just like in the selection with the help of check-box. I have an event embedded to the cell of the grid and wants to do some task with the help of the click event but it loses the previously selected rows when a new cell is being clicked. I want to keep the state of the rows selected earlier.

Phil
  • 7,065
  • 8
  • 49
  • 91
nikom
  • 71
  • 1
  • 1
  • 10

2 Answers2

0

In your grid-options set rowMultiSelectWithClick to true.

https://www.ag-grid.com/javascript-grid-selection/

Set to true to all multiple rows to be selected with a single click. E.g. if you click select one row, then click select another row, the first row will keep it's selection. Clicking a selected row in this mode will deselect the row. This is useful for touch devices where ctrl and shift clicking is not an option.

Phil
  • 7,065
  • 8
  • 49
  • 91
  • Okay , it is retaining the state of the rows selected but I want that ,when I click on a cell which has the function to do something when it is being clicked, it will retain the state of the previously selected rows and when another row with the click event is clicked, it will trigger the function based on the latest selected rows and not with all the rows selected. – nikom May 16 '18 at 05:43
  • I have this cell and wants to trigger a function when it is being clicked based on the latest row selected and not from all the rows that have been selected previously, so it has to access the last selected row and then do the computation based on the latest row : {headerName: "File Name", field: "graphs", cellStyle: {color:'blue'}, onCellClicked : (deleteClickEvent)=> {this.mainContentComponent.getPageCount();} – nikom May 16 '18 at 05:51
  • when you click on a cell it will get un/selected. what you can do is to not use aggrid-selection at all but use `rowNode.setData(data)` and `gridOptions.getRowStyle = ((params: GridRowParams) => {...});` – Phil May 16 '18 at 06:34
  • What I mean is you can call rowNode.setData(data) only in the cells that are supposed to select or unselect the row – Phil May 16 '18 at 06:38
0

Can you Try this for multiple selection with current selected row. In html,

<ag-grid-angular
#agGrid
style="width: 100%; height: 100%;"
id="myGrid"
class="ag-theme-balham"
[columnDefs]="columnDefs"
[rowSelection]="rowSelection"
(rowSelected)="onRowSelected($event)"
[rowMultiSelectWithClick]="true"
(gridReady)="onGridReady($event)"
(click)="getRowSelected($event)"
></ag-grid-angular>

In your typescript component

onRowSelected(event) { window.alert("row " + event.node.data.athlete + " selected = " + event.node.selected); }

Hope this will help you!

Sanoj_V
  • 2,936
  • 1
  • 12
  • 28
  • Thanks for this, but I already have an event set for a particular column in the grid which is working fine but I need to get the latest selected node and trigger the function based on the last row selected and not from all the rows selected, I have already used the cell click event but just wanted to access the instance of the last selected row in order to do the required computation. – nikom May 16 '18 at 10:24