startEditingCell in ag-grid does not work when Item has just been added

Viewed 2066

I am trying to have my ag-grid start editing as soon as a new item is added. It works when grid has data already but if it's the first item in the grid it does not work.

var a = $scope.gridOptions.api.updateRowData({add: [newItem]});

$scope.gridOptions.api.refreshCells({force:true}); // does not help
$scope.gridOptions.api.startEditingCell({
    rowIndex: a.add[0].rowIndex,
    colKey: 'Note'
});

using ag-grid version 12.0.2. Console shows nothing.

2 Answers

The question showed AngularJS code.
Here's an example what you'd need to do, using regular Angular.

  getContextMenuItems(params) {
    var result = [
      {
        name: 'Add new row',
        action: function() {
          //  Add a new row at the start of our agGrid's data array
          params.context.rowData.unshift({});
          params.api.setRowData(params.context.rowData);
          params.api.refreshCells();

          //  Get the name of the first column in our grid
          let columnField = params.column.userProvidedColDef.field;

          //  Highlight the left-hand cell in our new row, and start editing it
          params.api.setFocusedCell(0, columnField, null);
          params.api.startEditingCell({
              rowIndex: 0,
              colKey: columnField,
              rowPinned: null
          });
        },
        icon: '<img src="../../assets/images/icnAdd.png" width="14"/>'
      }
    ];
    return result;
  }

Hope this helps.

Related