2014-09-21 18 views
-1

我有兩個NG-格住在同一個$scope,它們都具有可編輯單元格的列,即:enableCellEdit: true哪個ng-grid觸發了ngGridEventEndCellEdit?

我知道我能應付這樣的觸發事件:

$scope.$on('ngGridEventEndCellEdit', function(event) { 
    var product = event.targetScope.row.entity; 

    console.log(product); 
}); 

問題是..我怎麼知道哪個網格觸發了事件?兩個網格消耗不同的列表(網格的data屬性),但這些列表包含相同類型的實例。

event裏面是否有包含網格ID的任何屬性?

+0

爲什麼downvote? – sports 2015-05-12 21:12:36

回答

0

我有同樣的麻煩和解決它。

我有三個網格,每個cellEditableTemplate我註冊ng單擊單元格,從而選擇單元格編輯的開始和結束事件的下一個來源。該setMethod(),只是設置全局變量$scope.thisGridUpdate

$scope.targetTypeDefs = [ { 
    field : 'id', 
    displayName : '#', 
    enableCellEdit : false, 
    width : 50 
}, { 
    field : 'desc', 
    displayName : 'Type Description', 
    enableCellEdit : true, 
    cellEditableCondition : 'row.selected', 
     editableCellTemplate : '<input ng-class="\'colt\' + col.index" \ 
      ng-input="COL_FIELD" \ 
      ng-model="COL_FIELD" \ 
      ng-model-options="{ updateOn : \'default blur\' }" \ 
      ng-click="setMethod(\'saveTargetType\')"/>' 
} ]; 
$scope.targetTypeGrid = { 
    data : 'targetTypeData', 
    showSelectionCheckbox : true, 
    selectWithCheckboxOnly : true, 
    multiSelect : false, 
    enableCellEditOnFocus : true, 
    columnDefs : 'targetTypeDefs' 
}; 

接下來你只是趕上並捕獲結束單元格編輯事件在你的正常活動ngGridEventEndCellEdit消費者,像這樣:

$scope.setMethod = function(name) { 
    console.log("clicked on ", name); 
    $scope.thisGridUpdate = name; 
}; 
$scope.$on('ngGridEventEndCellEdit', function(evt, other) { 
    console.log("ended edit on ", $scope.thisGridUpdate, "with " , evt.targetScope.row.entity); 
    console.log(evt.targetScope.row); 
    if ($scope.thisGridUpdate === 'saveServerType') { 
     EntityMgt.saveServerType(evt.targetScope.row.entity); 
    } 
    else if ($scope.thisGridUpdate === 'saveOsVersion') { 
     EntityMgt.saveOsVersion(evt.targetScope.row.entity); 
    } 
    else if ($scope.thisGridUpdate === 'saveTargetType') { 
     EntityMgt.saveTargetType(evt.targetScope.row.entity); 
    } 
}); 
相關問題