Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With AG Grid, prevent row click event when cell is clicked?

I'd like to stop event propagation on all cell clicks since I'm using onRowClicked to do some actions. When a user clicks on something inside a cell (like an input field), I don't want the row click to be triggered.

Any thoughts?

I'm using Angular 2/4 for this.

like image 523
Charlie Avatar asked Dec 14 '17 21:12

Charlie


People also ask

How do I turn off rows on 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 prevent closing of cell editing in AG grid on other cell focus?

If you want the grid to stop editing when focus leaves the cell or the grid, set the grid property stopEditingWhenCellsLoseFocus = true .

How do you get the selected row value 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.

How do I disable AG grid checkbox?

gridOptions. suppressCellSelection = true; but this just hides the checkbox whereas i need to show the checkbox in disable mode. Thanks. never used this lib, but it looks like that you have to add some property to each row you want to disable, instead of looking for a grid-wide solution.


Video Answer


2 Answers

None of the past suggestions worked for me. AG Grid may have changed the API behavior. Even event.stopPropagation() on onCellClicked would not stop onRowClicked from firing.

What I ultimately did was to remove onRowClicked altogether and handle everything in onCellClicked. onRowClicked does not have an attribute on which column the click event generated from, onCellClicked does!

function cellClickedHandler(e) {
  if (e.column.colId === 'col1') {
    // Handle specific cell
  } else {
    // Handle all other cells, similar to rowClicked
  }
}
like image 176
Albi Avatar answered Sep 19 '22 00:09

Albi


  <ag-grid-angular style="width: 100%;   height: 168px;" class="ag-theme-fresh" 
    [rowData]="rowData" [columnDefs]="columnDefs"
    [enableFilter]="true" [enableSorting]="true" 
    [getRowNodeId]="getRowNodeId" [rowSelection]="rowSelection" 
    (selectionChanged)="onSelectionChanged($event)"
    (gridReady)="onGridReady($event)" 
    [suppressRowClickSelection]="true"
    (cellClicked)='onCellClicked($event)'>
  </ag-grid-angular>

Use [suppressRowClickSelection]="true" to prevent the row click

like image 27
Farida Anjum Avatar answered Sep 21 '22 00:09

Farida Anjum