2013-11-20 110 views
1

我有一個網格底部有編輯和刪除按鈕的網格。當沒有行被選中時,兩個按鈕都被禁用。ng-grid通過單擊網格外部的按鈕來刪除一行

我想知道正確的方法來刪除NG-電網一排,當選擇一行。

我找不到他們的website或任何其例子wiki

+1

從網格的源數據中刪除選定的項目。 –

+0

你能提供一個例子嗎? – Pritish

+0

我怎樣才能降低你的評論? – nottinhill

回答

1

我原來和選擇......像這樣的一個簡單比較:

angular.forEach($scope.gridOptions.selectedItems, function(index) { 

    var deleteIndex = $scope.originalResource.indexOf(index); 

    if (deleteIndex > -1){ 
     $scope.originalResource.splice(deleteIndex,1); 
    } 
}); 

然後不選行我這樣做:$scope.selections.splice(0)

0
use this it works for both multiple rows or single row selection 
$scope.mySelections = []; 
      $scope.gridOptions = { 
       data :'data', 
       selectedItems : $scope.mySelections, 
       showSelectionCheckbox : true 
      } 


$scope.delItem = function() { 

    for (var i = 0; i < $scope.mySelections.length; i++) { 
     var index = $scope.data.indexOf($scope.mySelections[i]); 
     if (index != -1) { 
      $scope.data.splice(index, 1); 
     } 
    } 
} 
相關問題