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.savedRow基本的に、データを使用して行データを設定する代わりに$grid.p.data、行を復元するときに行データを設定するために使用します。

修正に関するフィードバックを探していると思います。このようにソース コードを変更することで、意図しない結果が生じる可能性はありますか? ソース コードを変更せずにこの修正を行う方法はありますか (私のチームが JQGrid を維持および更新しやすくなります)? 私は何かを正しく理解していませんか?:)

助けてくれてありがとう!バグのデモが役立つ場合は、作成できます。ここでは個人の Web サーバーにアクセスできません。

4

1 に答える 1

0

あなたの提案の重要な問題の 1 つは、$grid.p.data常に存在するとは限らないことです。「古典的な」グリッドをdatatype: 'json'またはdatatype: 'xml'で使用し、使用しない場合loadonce: true、未定義dataのパラメーターがあります。私は Tony に のコードを変更しaddJSONData、パラメーターもaddXmlData埋めるように提案しました ( code の部分を参照してください) が、いずれにせよ、現在の jqGrid の実装が常に満たされるとは限りません。そのため、ケースには使用できません。datadata$t.p.data

于 2012-01-12T14:19:18.650 に答える