【问题标题】:What is the effect of paging on jqgrid's getChangedCells method when using clientArray(clientside) for editing?使用clientArray(clientside)进行编辑时,分页对jqgrid的getChangedCells方法有什么影响?
【发布时间】:2011-12-28 03:46:12
【问题描述】:
我正在使用带有 clientArray 选项的 jqgrid 进行编辑;我的网格正在使用分页; jqgrid getChangedCells 方法是否会返回正确的更改行,即使在多次更改页面之后服务器中的数据可能已更改? - 例如,如果服务器提供了新行,如果我返回页面,这些新行现在将出现在我的网格中;
不会有 rowId 冲突 - 新的 rowIds 将指向与新数据可用之前不同的行吗?
我想我总是可以通过自动递增的主键来排序我的服务器数据?..
【问题讨论】:
标签:
jquery
jqgrid
pagination
【解决方案1】:
我认为,当您存储时,如果同一行已经存在,那么最好覆盖retainedChanges 中的现有行,因为用户可能会一次又一次地覆盖现有行。
【解决方案2】:
今天在实验中发现;分页(服务器端)一个 jqgrid 清除 getChangedCells 的结果;我必须创建一个实用函数来存储 getChangedCells 数组,以便它在分页中持续存在;
我这样做是为了可以单独提交所有更改
在 jqgrid 选项中,我有类似的内容:
('#grid').jqgrid({
....
cellEdit:true,
cellSubmit:'clientArray',
colModel: [ {...,editable:true,
dataInit:function(el){
el.autocomplete({...});
}...} ... ],
afterSaveCell:function(){
$.retainChangesOnPaging();
}
....
});
在实用程序 retainChangesOnPaging 我有类似的东西:
(function(){
var retainedChanges;
retainedChanges = new Array();
$.retainChangesOnPaging = function(){
var changedCells = ('#grid').jqGrid('getChangedCells');
// loop over changedCells array, removing duplicates if you want to...
return retainedChanges.push(/* this is inside the loop; push current value to array*/);
....
}
$.getRetainedChanges = function(){
return retainedChanges;
}
})(jQuery);
然后当我准备好向服务器提交所有更改时,我调用 $.getRetainedChanges
另一个问题:我使用 retainChangesOnPaging 的方式是否正确?尽管代码有效,但似乎有些问题-我可以以任何方式使它变得更好吗?我的关闭可以吗?