1

我注意到当使用内联行编辑(通过 将行置于编辑状态$grid.jqGrid('editRow', rowId, ...etc))然后在$grid.jqGrid('restoreRow',rowToRestore);不实际编辑行的情况下恢复行()时,会将格式化列设置为$grid.p.data[{indexofrowrestored}][{columnname}]格式化值而不是列的原始值。

这样做的后果是恢复的行的工具栏过滤器输入将根据格式化值而不是未格式化值过滤行(就像所有其他行一样)。

我浏览了 JQGrid 源代码并提出了解决此问题的方法(JQGrid v4.3.1)。我更改了restoreRow函数中的一些代码来解决我的问题:

盯着第 9038 行jquery.jqGrid.src.js(见添加代码的注释):

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.savedRowdata 将行数据设置为,而是使用 将$grid.p.data行数据设置为在恢复行时。

我想我正在寻找有关我的修复的反馈 - 通过以这种方式更改源代码,我可能会遇到任何意想不到的后果吗?有没有一种方法可以在不更改源代码的情况下实现此修复(我的团队更容易维护和更新 JQGrid)?我没有正确理解某些东西吗?:)

非常感谢您的帮助!如果该错误的演示会有所帮助,我可以创建一个。我在这里无法访问我的个人网络服务器。

4

1 回答 1

0

您的建议的一个重要问题是它$grid.p.data并不总是存在。如果您使用带有datatype: 'json'or的“经典”网格datatype: 'xml'并且您不使用loadonce: true您将有未定义的data参数。我建议 Tony 修改代码addJSONDataaddXmlData填充data参数(参见代码部分),但无论如何,jqGrid 的当前实现并不总是填充data。所以$t.p.data不能用在这种情况下。

于 2012-01-12T14:19:18.650 回答