Change slickgrid cell data after edit

无人久伴 提交于 2021-02-16 06:21:52

问题


I'm using Slickgrids with alot of success. I have ajax edits all working - but I'm trying to add a piece of functionality;

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;
               } }); });

回答1:


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();

Hope that helps!



来源:https://stackoverflow.com/questions/12077950/change-slickgrid-cell-data-after-edit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!