javascript 编辑后更改 slickgrid 单元格数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12077950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change slickgrid cell data after edit
提问by Laurence
I'm using Slickgrids with alot of success. I have ajax edits all working - but I'm trying to add a piece of functionality;
我使用 Slickgrids 取得了很多成功。我有 ajax 编辑所有工作 - 但我正在尝试添加一个功能;
Below is my code which allows me to update cells - it works as intended - but I want to be able to change the cell after it has been editted with the returned value from the json data. See my code below - I have put in capitals where I need a command to update the editted cell with the new returned data
下面是我的代码,它允许我更新单元格 - 它按预期工作 - 但我希望能够在使用 json 数据的返回值对其进行编辑后更改单元格。请参阅下面的代码 - 我在需要使用新返回数据更新编辑过的单元格的命令的地方输入了大写字母
grid.onCellChange.subscribe(function(e, args) {
var dataString = "col="+grid.getColumns()[args.cell].name+"&row="+args.item.new_training_calendar_id+"&value="+data[args.row][grid.getColumns()[args.cell].field];
$.ajax({
type: "POST",
url: "mydomain/update_cell",
data: dataString, dataType: "json",
success: function(a) {
if(a.status != "ok") {
alert(a.msg);
undo();
} else {
alert(a.msg);
**CHANGE_CELL_HERE TO (a.newdata);**
}
return false;
} }); });
回答by ganeshk
If you are using DataView
in your grid, you can use:
如果您DataView
在网格中使用,则可以使用:
grid.invalidateRow(args.row);
var row = dataView.getItem(args.row);
row[grid.getColumns()[args.cell].field] = a.msg;
dataView.updateItem(args.item.id, row);
grid.render();
If you are using a plain grid instead, you can use:
如果您使用的是普通网格,则可以使用:
grid.invalidateRow(args.row);
data[args.row][grid.getColumns()[args.cell].field] = a.msg;
grid.render();
Hope that helps!
希望有帮助!