Angular JS UI-Grid Delete Row

后端 未结 5 574
野趣味
野趣味 2021-02-05 16:47

I\'m new to ui-grid and I\'m trying to implement a table in AngularJS as shown in the picture below. I\'m trying to select a row and delete it using a delete button

5条回答
  •  眼角桃花
    2021-02-05 17:45

    Please see a working example of how to delete a row here. http://plnkr.co/edit/6TiFC6plEMJMD4U6QmyS?p=preview

    The key is to use indexOf(row.entity) and not relying on row.index as it doesn't dynamically get updated.

    $scope.deleteRow = function(row) {
      var index = $scope.gridOptions.data.indexOf(row.entity);
      $scope.gridOptions.data.splice(index, 1);
    };
    

    Generic approach

    function deleteRow(row,grid) {
       var i = grid.options.data.indexOf(row.entity);
       grid.options.data.splice(i, 1);
    }
    

提交回复
热议问题