Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQGrid工具栏筛选并还原具有格式化列的处于编辑状态的行_Javascript_Jquery_Jqgrid_Jqgrid Formatter - Fatal编程技术网

Javascript JQGrid工具栏筛选并还原具有格式化列的处于编辑状态的行

Javascript JQGrid工具栏筛选并还原具有格式化列的处于编辑状态的行,javascript,jquery,jqgrid,jqgrid-formatter,Javascript,Jquery,Jqgrid,Jqgrid Formatter,我注意到这样一种行为:当使用内联行编辑(通过$grid.jqGrid('editRow',rowId,…等)将行置于编辑状态时,),然后在不实际编辑行的情况下还原行($grid.jqGrid('restoreRow',rowToRestore);),将设置格式化列的$grid.p.data[{indexofrowered}][{columnname}]转换为格式化值,而不是列的原始值 这样做的结果是,还原行的工具栏过滤器输入将根据格式化的值而不是未格式化的值(与所有其他行一样)过滤该行 我浏览了

我注意到这样一种行为:当使用内联行编辑(通过
$grid.jqGrid('editRow',rowId,…等)将行置于编辑状态时,
),然后在不实际编辑行的情况下还原行(
$grid.jqGrid('restoreRow',rowToRestore);
),将设置格式化列的
$grid.p.data[{indexofrowered}][{columnname}]
转换为格式化值,而不是列的原始值

这样做的结果是,还原行的工具栏过滤器输入将根据格式化的值而不是未格式化的值(与所有其他行一样)过滤该行

我浏览了JQGrid源代码,并为这个问题找到了解决方案(JQGrid v4.3.1)。我在
restoreRow
函数中更改了一些代码,解决了我的问题:

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

restoreRow:函数(rowid,afterrestorefunc){
//兼容模式旧版本
var args=$.makeArray(arguments).slice(1),o={};
if($.jgrid.realType(args[0])=“对象”){
o=args[0];
}否则{
if($.isFunction(afterrestorefunc)){o.afterrestorefunc=afterrestorefunc;}
}
o=$.extend(true,$.jgrid.inlineEdit,o);
//端兼容
返回此值。每个(函数(){
var$t=this,fr,d,ind,ares={};//更新:添加了变量“d”
if(!$t.grid){return;}
ind=$($t).jqGrid(“getInd”,rowid,true);
如果(ind==false){return;}

对于(var k=0;k您建议的一个重要问题是,
$grid.p.data
并不总是存在。如果您使用“经典”带有
datatype:'json'
datatype:'xml'
的网格,并且您不使用
loadonce:true
您将拥有未定义的
data
参数。我建议Tony修改
addJSONData
addXmlData
的代码来填充
数据
参数(请参阅)但无论如何,jqGrid的当前实现并不总是填充
数据
。因此
$t.p.data
不能用于这种情况。

Ahh,目前我使用
loadonce:true
datatype:'json'
。在我们的应用程序中,我可能会在特定的网格中更改为
loadonce:false
,以提高per性能,因为我们有可能从填充它的查询中检索数万个结果。因为在这种情况下,过滤将在服务器端完成,
restoreRow
中我需要
$t.p.data
来修复“bug”的位置将不再需要。我想我只需要检查
$t.p.data
中的空值和空值在这种情况下使用
$t.p.savedRow
。非常感谢您让我知道
$t.p.data
没有被填充!
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);
        }
    });
},