Ag-grid Angular 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.

2 answers

  • answered 2018-05-16 05:29 Phil

    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.

  • answered 2018-05-16 06:34 Sanoj_V

    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!