如何禁用 saveRow 事件 ui-grid
How to disable saveRow event ui-grid
我正在使用 ui-grid 在 UI 中显示我的 table。我有一个要求 ui 不希望 table 自动保存数据的地方。我希望用户编辑 table 中的所有数据并单击按钮更新所有编辑的数据。
以上行为工作正常,但我遇到的唯一问题是每当用户连续编辑一个单元格时,几秒钟后,该单元格就会变成灰色并且无法显示table。在浏览器 cnsole 上我收到此错误:
引发 saveRow 事件时未 return 承诺,要么没有人在侦听事件,要么事件处理程序没有 return 承诺
由于上面的JS错误,整行变成un-editable。
如何告诉 ui-grid 不保存数据,除非我点击我的按钮。
如果我处理 saveRow 事件,那么我的按钮不起作用。请在这方面帮助我。
相关代码片段如下:
var grid = {
data : 'hwData['+key+']',
paginationPageSizes: [25, 50, 75],
paginationPageSize: 25,
enableGridMenu: true,
enableFiltering: true,
enableSelectAll: true,
enableColumnResize : true,
exporterCsvFilename: 'myFile.csv',
exporterMenuPdf: false,
exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
onRegisterApi: function(gridApi){
$scope.gridApi.push(gridApi);
gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
if(oldValue == newValue){
return false;
}
$("#test").prepend('<font color= "red"> ' +colDef.name+ 'Edited ');
})
},
..............some more code
..............
$.ajax({
type:'POST',
url:'/HardwareInventory/ajax/storage/edit_owned_storage',
data: jsonHostNames,
dataType:"json",
contentType: "application/json; charset=utf-8",
success : function(result){
if(result.status == "Success"){
location.reload(true);
}else{
bootbox.alert("Either hostname is not correct or you don't have permission to edit this team's data");
}
},
statusCode: {
500: function(){
alert("Oops!, there has been an internal error");
}
},
complete: function(result){
}
});
}
});
@Jha:看看下面的 url 我刚刚添加了伪造的保存方法,在您在其中定义保存功能之前,它不会保存任何数据。
http://plnkr.co/edit/T0TLGLpLsk25vY6SUnzR?p=preview
//保存每一行数据
gridApi.rowEdit.on.saveRow($scope, $scope.saveRow);
$scope.saveRow = function (rowEntity) {
var promise = $q.defer();
$scope.gridApi.rowEdit.setSavePromise(rowEntity, promise.promise);
promise.resolve();
};
以上代码将解决您的错误"A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise"。不要忘记在控制器功能中添加“$q”。希望你的保存功能也能正常使用。
在你的网格选项中设置"rowEditWaitInterval :-1",默认情况下它永远不会调用saveRow方法,所以你可以在你的自定义方法中保存修改的数据。
你可以像这样访问 dirtyrows
var dirtyRows = $scope.gridApi.rowEdit.getDirtyRows($scope.gridApi.grid);
我正在使用 ui-grid 在 UI 中显示我的 table。我有一个要求 ui 不希望 table 自动保存数据的地方。我希望用户编辑 table 中的所有数据并单击按钮更新所有编辑的数据。
以上行为工作正常,但我遇到的唯一问题是每当用户连续编辑一个单元格时,几秒钟后,该单元格就会变成灰色并且无法显示table。在浏览器 cnsole 上我收到此错误:
引发 saveRow 事件时未 return 承诺,要么没有人在侦听事件,要么事件处理程序没有 return 承诺
由于上面的JS错误,整行变成un-editable。 如何告诉 ui-grid 不保存数据,除非我点击我的按钮。
如果我处理 saveRow 事件,那么我的按钮不起作用。请在这方面帮助我。
相关代码片段如下:
var grid = {
data : 'hwData['+key+']',
paginationPageSizes: [25, 50, 75],
paginationPageSize: 25,
enableGridMenu: true,
enableFiltering: true,
enableSelectAll: true,
enableColumnResize : true,
exporterCsvFilename: 'myFile.csv',
exporterMenuPdf: false,
exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
onRegisterApi: function(gridApi){
$scope.gridApi.push(gridApi);
gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
if(oldValue == newValue){
return false;
}
$("#test").prepend('<font color= "red"> ' +colDef.name+ 'Edited ');
})
},
..............some more code
..............
$.ajax({
type:'POST',
url:'/HardwareInventory/ajax/storage/edit_owned_storage',
data: jsonHostNames,
dataType:"json",
contentType: "application/json; charset=utf-8",
success : function(result){
if(result.status == "Success"){
location.reload(true);
}else{
bootbox.alert("Either hostname is not correct or you don't have permission to edit this team's data");
}
},
statusCode: {
500: function(){
alert("Oops!, there has been an internal error");
}
},
complete: function(result){
}
});
}
});
@Jha:看看下面的 url 我刚刚添加了伪造的保存方法,在您在其中定义保存功能之前,它不会保存任何数据。 http://plnkr.co/edit/T0TLGLpLsk25vY6SUnzR?p=preview
//保存每一行数据
gridApi.rowEdit.on.saveRow($scope, $scope.saveRow);
$scope.saveRow = function (rowEntity) {
var promise = $q.defer();
$scope.gridApi.rowEdit.setSavePromise(rowEntity, promise.promise);
promise.resolve();
};
以上代码将解决您的错误"A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise"。不要忘记在控制器功能中添加“$q”。希望你的保存功能也能正常使用。
在你的网格选项中设置"rowEditWaitInterval :-1",默认情况下它永远不会调用saveRow方法,所以你可以在你的自定义方法中保存修改的数据。 你可以像这样访问 dirtyrows
var dirtyRows = $scope.gridApi.rowEdit.getDirtyRows($scope.gridApi.grid);