ag-gridag-grid-ng2

ag-grid loses focus after refresh


I'm using ag-grid in Angular 4.x. Whenever the grid is refreshed it loses focus. This seems to be a bug in ag-grid.

Is there any workaround, like setting the focus back to the grid, so that keyboard navigation still functions?

Cheers, Seeschorle


Solution

  • Here is my solution:

       private bringFocusBack() {
          let cell = this.gridOptions.api.getFocusedCell();
    
          if ( cell ) {
             this.gridOptions.api.setFocusedCell( cell.rowIndex, cell.column );
          }
       }
    

    Call this method after doing the refresh:

    this.gridOptions.api.refreshRows( rowsToRefresh );
    this.bringFocusBack();