我有一个带有额外行.columnDefs的可编辑表。我在表中添加了一个grid api,以便在发生变化时获得警报:
$scope.gridOptions.onRegisterApi = function (gridApi) {
//set gridApi on scope
$scope.gridApi = gridApi;
gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
if (newValue !== oldValue) {
alert('edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue);
}
});
};
我不知道如何在columnDefs中使用它。我试过$scope.gridOptions.columnDefs.onRegisterApi = function (gridApi) {}
但这不起作用。我必须获取此子行中已更改的信息。
答案 0 :(得分:2)
$scope.gridOptions.columnDefs.onRegisterApi = function (gridApi) ...
无法正常工作,因为onRegisterApi
不是columnDefs
的属性 - 它直接属于gridOptions
。
如果您只想观察特定行/列或某些此类组合的更改,请按处理函数中的名称进行过滤。
答案 1 :(得分:-1)
我没有看到你的问题,如果你想知道什么行,列改变了,你的代码是对的。
gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
$scope.msg.lastCellEdited = 'edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue ;
console.log('edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue);
$scope.$apply();
});
rowEntity是修饰符的数据行。 ColDef是编辑过的精确列。
再次尝试或在您的问题中解释更多。