2012-01-11 15 views
1

インライン行編集(行を編集状態にして$grid.jqGrid('editRow', rowId, ...etc)を入力)し、実際に行を編集せずに行($grid.jqGrid('restoreRow',rowToRestore);)を復元すると、書式設定された列の$grid.p.data[{indexofrowrestored}][{columnname}]は、列の元の値ではなく書式設定された値に設定されます。JQGridツールバーフィルタと書式設定された列で編集状態の行を復元する

この結果、復元された行のツールバーのフィルタ入力は、書式なしの値ではなく書式設定された値に基づいて行をフィルタリングします(他のすべての行と同様)。

私はJQGridソースを使い、この問題(JQGrid v4.3.1)の解決策を考え出しました。代わりに行を設定する$grid.p.savedRowデータを使用するのでは、基本的に

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); 
     } 
    }); 
}, 

jquery.jqGrid.src.jsのライン9038を見つめる(追加されたコードのコメントを参照してください):私は私の問題を解決しrestoreRow機能にいくつかのコードを変更しました私は$grid.p.dataを使用して行を復元するときと同じように行データを設定します。

このようにソースコードを変更することで、意図しない結果が出ることはありますか?ソースコードを変更せずにこの修正を達成できる方法はありますか?私のチームがJQGridを維持し更新する方が簡単ですか?私は何かを正しく理解していないのですか? :)

ありがとうございました!バグのデモが参考になる場合は、作成することができます。私はここに私の個人的なウェブサーバーへのアクセスを持っていません。

答えて

0

あなたの提案の重要な問題の1つは、$grid.p.dataが必ずしも存在しないことです。 datatype: 'json'またはdatatype: 'xml'の「古典的」グリッドを使用していて、loadonce: trueを使用しない場合は、dataパラメータが未定義になります。私はaddJSONDataaddXmlDataのコードをdataのパラメータ(the part of codeを参照)に書き換えるようにTonyに提案しましたが、現状のjqGridの実装では必ずしもdataとは限りません。したがって$t.p.dataはこのケースでは使用できません。

+0

現在、私は 'loadonce:true'と' datatype: 'json''を使用しています。私たちはおそらく、アプリケーションの特定のグリッドで 'loadonce:false'に変更して、より多くのパフォーマンスを得ることができます。この場合、フィルタリングはサーバー側で行われるため、 'bug'を修正するために '$ t.p.data'が必要な' restoreRow'の場所は必要ありません。私は、nullの場合は '$ t.p.data'をチェックし、その場合は' $ t.p.savedRow'を使うだけです。私に '$ t.p.data'についての情報を提供してくれてありがとう! – icats

+0

@icats:ようこそ! – Oleg