2015-03-19 55 views
0

我有兩個NG-電網頁,我想用兩個相應的ngGridEventEndCellEdit事件:如何區分NG-電網事件,在單頁兩個網格

<div id="grid1" class="gridStyle" ng-grid="gridOptions1"></div> 
<div id="grid2" class="gridStyle" ng-grid="gridOptions2"></div> 

function HomeCtrl($scope, $http) { 
$scope.columns = [{ field: 'name', displayName: 'Name', enableCellEdit: false }, { field: 'age', displayName: 'Age', enableCellEdit: false }];   

$scope.gridOptions1 = { 
    data: 'myData', enablePinning: true, enableCellEdit: true, enableRowSelection: false, 
    columnDefs: 'columns' 
}; 

$scope.columns2 = [{ field: 'name1', displayName: 'Name', enableCellEdit: false }, { field: 'Age1', displayName: 'Age', enableCellEdit: false }];   

$scope.gridOptions2 = { 
    data: 'myData2', enablePinning: true, enableCellEdit: true, enableRowSelection: false, 
    columnDefs: 'columns2' 
}; 
$scope.myData = [{name: "Moroni", age: 50}, 
        {name: "Tiancum", age: 43}, 
        {name: "Jacob", age: 27}, 
        {name: "Nephi", age: 29}, 
        {name: "Enos", age: 34}]; 

$scope.myData2 = [{name1: "Moroni", age1: 50}, 
         {name1: "Tiancum", age1: 43}, 
         {name1: "Jacob", age1: 27}, 
         {name1: "Nephi", age1: 29}, 
         {name1: "Enos", age1: 34}]; 
} 

有兩個網格,和我想根據網格編號在單元格編輯上選擇ngGridEventEndCellEdit兩個不同的事件。我怎樣才能做到這一點 ?

//for grid1 
$scope.$on('ngGridEventEndCellEdit', function (data) { 

}; 

//for grid2 
$scope.$on('ngGridEventEndCellEdit', function (data) { 

}; 

回答

0

對於這個特定的事件中,我們可以做到這一點的一種方法是:

$scope.gridOptions1 = { 
    //options for grid 1 
} 

$scope.gridOptions2 = { 
    //options for grid 2 
} 

$scope.$on('ngGridEventEndCellEdit', function(event) { 
    switch(event.targetScope.gridId) { 
     case $scope.gridOptions1.$gridScope.gridId: 
     //handle the event for grid 1 
     break; 
     case $scope.gridOptions2.$gridScope.gridId: 
     //handle the event for grid 2 
     break; 
    } 
});