编辑后更改slickgrid单元格数据 [英] Change slickgrid cell data after edit
问题描述
我使用Slickgrids取得了很多成功.我已经完成了所有工作的ajax编辑-但我正在尝试添加一项功能;
I'm using Slickgrids with alot of success. I have ajax edits all working - but I'm trying to add a piece of functionality;
下面是我的代码,该代码允许我更新单元格-可以按预期工作-但我希望能够使用json数据中的返回值对单元格进行编辑后再进行更改.请参阅下面的代码-我在大写字母处输入了需要使用新返回的数据更新已编辑单元格的命令
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
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;
} }); });
推荐答案
如果在网格中使用 DataView
,则可以使用:
If you are using DataView
in your grid, you can use:
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();
希望有帮助!
这篇关于编辑后更改slickgrid单元格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!