JQGridtoolbar过滤并恢复具有格式化列的处于编辑状态的行
JQGrid toolbar filter and restoring a row in edit state with formatted columns
我注意到,当使用内联行编辑(通过$grid.jqGrid('editRow', rowId, ...etc)
将行置于编辑状态),然后在不实际编辑行的情况下恢复行($grid.jqGrid('restoreRow',rowToRestore);
)时,会将格式化列的$grid.p.data[{indexofrowrestored}][{columnname}]
设置为格式化值,而不是列的原始值。
这样做的结果是,恢复的行的工具栏过滤器输入将根据格式化的值而不是未格式化的值来过滤该行(就像它对所有其他行所做的那样)。
我浏览了JQGrid的源代码,并为这个问题找到了解决方案(JQGridv4.3.1)。我更改了restoreRow
函数中的一些代码,以解决我的问题:
盯着jquery.jqGrid.src.js
的9038行(添加代码见注释):
restoreRow : function(rowid, afterrestorefunc) {
// Compatible mode old versions
var args = $.makeArray(arguments).slice(1), o={};
if( $.jgrid.realType(args[0]) === "Object" ) {
o = args[0];
} else {
if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
}
o = $.extend(true, $.jgrid.inlineEdit, o );
// End compatible
return this.each(function(){
var $t= this, fr, d, ind, ares={}; //UPDATED: added the variable 'd'
if (!$t.grid ) { return; }
ind = $($t).jqGrid("getInd",rowid,true);
if(ind === false) {return;}
for( var k=0;k<$t.p.savedRow.length;k++) {
if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
}
//----------------------------------------------------------------------------
//ADDED: added this for-loop
// get a hold of the $t.p.data array row with the ID of the
// row being restored; this row contains the original, unformatted
// data that came from the server while $t.p.savedRow contains
// what appears to be formatted column data; this is messing
// up the toolbar filter accuracy (which filters on original, unformatted
// data) when the row is restored
for( var k=0;k<$t.p.data.length;k++) {
if( $t.p.data[k].id == rowid) {d = k; break;}
}
//END EDIT
//----------------------------------------------------------------------------
if(fr >= 0) {
if($.isFunction($.fn.datepicker)) {
try {
$("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
} catch (e) {}
}
$.each($t.p.colModel, function(i,n){
if(this.editable === true && this.name in $t.p.savedRow[fr] && !$(this).hasClass('not-editable-cell')) {
//EDIT: this line was edited to set ares[this.name] to
//the original, unformatted data rather than the saved row data
//so, below, when setRowData method is called, it is being set
//to original data rather than formatted data
ares[this.name] = $t.p.data[d][this.name];
//END EDIT
}
});
$($t).jqGrid("setRowData",rowid,ares);
$(ind).attr("editable","0").unbind("keydown");
$t.p.savedRow.splice(fr,1);
if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
setTimeout(function(){$($t).jqGrid("delRowData",rowid);},0);
}
}
if ($.isFunction(o.afterrestorefunc))
{
o.afterrestorefunc.call($t, rowid);
}
});
},
基本上,当恢复行时,我使用$grid.p.data
来设置行数据,而不是使用$grid.p.savedRow
数据将行数据设置为。
我想我正在寻找关于我的修复的反馈——以这种方式更改源代码是否会带来任何意想不到的后果?有没有一种方法可以在不更改源代码的情况下实现这个修复(对我的团队来说更容易维护和更新JQGrid)?我是不是理解不正确?:)
非常感谢您的帮助!如果这个bug的演示有帮助,我可以创建一个。我在这里无法访问我的个人网络服务器。
您的建议中的一个重要问题是$grid.p.data
并不总是存在。如果将"经典"网格与datatype: 'json'
或datatype: 'xml'
一起使用,而不使用loadonce: true
,则会有未定义的data
参数。我建议Tony修改addJSONData
和addXmlData
的代码来填充data
参数(参见代码部分),但无论如何,jqGrid的当前实现并不总是填充data
。因此$t.p.data
不能用于该情况。
- CKEditor Widget-阻止编辑可编辑元素本身
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 高亮显示时编辑文本大小和颜色
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 将事件聚焦/模糊在可编辑内容的元素上
- 编辑HTML表的源数据
- ExtJS网格单元格编辑器,防止焦点松动问题
- 所见即所得编辑器适用于速度模板
- 如何在角度可编辑中应用于更改事件
- jqGrid如何处理事件在编辑列后输入键,这要归功于editRow
- 相对于另一个 css 元素定位一个元素,而不编辑 html
- 专注于加载时 iframe 中的内容可编辑正文
- 在 tinyMCE 中,将格式应用于非编辑区域
- 简单代码仅适用于某些编辑器,而不适用于其他任何地方
- 无法让单元格专注于内容可编辑脚本
- 实时表编辑不仅适用于文本框
- 在PaperJS中,允许用户编辑类似于TextItem的常规文本输入字段
- 使用下拉列表编辑器的剑道网格-线编辑(编辑自定义编辑器)
- 如何同步声明JS对象,然后用依赖于并发操作的数据编辑对象的属性
- 是否有办法编辑此脚本,使其仅适用于特定的选择类