jqgrid

2011-07-22 12 views
7

jqGridパラメータloadonce内のローカルデータを持つ行を削除する方法:真のURLがローカルデータの行を削除する方法 jqgrid

に設定されていない

削除ボタン

を行を選択し、押し

使用されているのみで、このエラーメッセージを抑制しますか? ダミーのURLや行削除を許可する他のアイデアを設定することは可能でしょうか? 追加と編集のフォームをローカルデータと併用することができればいいと思います。

  url: 'GetData', 
      datatype: "json", 
      multiselect: true, 
      multiboxonly: true, 
      scrollingRows : true, 
      autoencode: true, 
      loadonce: true, 
      prmNames: {id:"_rowid", oper: "_oper" }, 
      rowTotal: 999999999, 
      rownumbers: true, 
      rowNum: 999999999, 

アップデート1

オレグの答えから、私は、次の解決策に理解:

  1. 無効にjqGrid標準削除ボタン
  2. は、ツールバーに新しい削除ボタンを追加します。このボタンのクリックイベントの呼び出しから
  3. grid.jqGrid( 'delGridRow'、ROWID、myDelOptions)を提供します。

メソッド。 複数の行を選択できます。選択したすべての行を削除するには、このサンプルは1つだけ削除しますか?

削除、編集、追加ボタンがURLなしで機能するようにjqGridを変更する方がいいですか?現在、ローカルデータ編集のために常に成功を返すダミーのURLを渡す必要があります。

答えて

10

delRowDataメソッドを使用すると、ローカル行を削除できます。

delGridRowは、必要に応じてフォームの編集から使用できます。私はhereと記述し、フォーマッタのために使用しました: 'actions'(here,here、もともとはhereを参照してください)。

var grid = $("#list"), 
    myDelOptions = { 
     // because I use "local" data I don't want to send the changes 
     // to the server so I use "processing:true" setting and delete 
     // the row manually in onclickSubmit 
     onclickSubmit: function(options, rowid) { 
      var grid_id = $.jgrid.jqID(grid[0].id), 
       grid_p = grid[0].p, 
       newPage = grid_p.page; 

      // reset the value of processing option which could be modified 
      options.processing = true; 

      // delete the row 
      grid.delRowData(rowid); 
      $.jgrid.hideModal("#delmod"+grid_id, 
           {gb:"#gbox_"+grid_id, 
           jqm:options.jqModal,onClose:options.onClose}); 

      if (grid_p.lastpage > 1) {// on the multipage grid reload the grid 
       if (grid_p.reccount === 0 && newPage === grid_p.lastpage) { 
        // if after deliting there are no rows on the current page 
        // which is the last page of the grid 
        newPage--; // go to the previous page 
       } 
       // reload grid to make the row from the next page visable. 
       grid.trigger("reloadGrid", [{page:newPage}]); 
      } 

      return true; 
     }, 
     processing:true 
    }; 

と、更新

grid.jqGrid('delGridRow', rowid, myDelOptions); 

を使用:multiselect: truemyDelOptionsの場合には、次のように変更することができる:キーボードをサポートしました:

var grid = $("#list"), 
    myDelOptions = { 
     // because I use "local" data I don't want to send the changes 
     // to the server so I use "processing:true" setting and delete 
     // the row manually in onclickSubmit 
     onclickSubmit: function(options) { 
      var grid_id = $.jgrid.jqID(grid[0].id), 
       grid_p = grid[0].p, 
       newPage = grid_p.page, 
       rowids = grid_p.multiselect? grid_p.selarrrow: [grid_p.selrow]; 

      // reset the value of processing option which could be modified 
      options.processing = true; 

      // delete the row 
      $.each(rowids,function(){ 
       grid.delRowData(this); 
      }); 
      $.jgrid.hideModal("#delmod"+grid_id, 
           {gb:"#gbox_"+grid_id, 
           jqm:options.jqModal,onClose:options.onClose}); 

      if (grid_p.lastpage > 1) {// on the multipage grid reload the grid 
       if (grid_p.reccount === 0 && newPage === grid_p.lastpage) { 
        // if after deliting there are no rows on the current page 
        // which is the last page of the grid 
        newPage--; // go to the previous page 
       } 
       // reload grid to make the row from the next page visable. 
       grid.trigger("reloadGrid", [{page:newPage}]); 
      } 

      return true; 
     }, 
     processing:true 
    }; 

を更新し削除操作で「削除」ボタンをデフォルトに設定する追加することができますdelSettings追加オプション

afterShowForm: function($form) { 
    var form = $form.parent()[0]; 
    // Delete button: "#dData", Cancel button: "#eData" 
    $("#dData",form).attr("tabindex","1000"); 
    $("#eData",form).attr("tabindex","1001"); 
    setTimeout(function() { 
     $("#dData",form).focus(); // set the focus on "Delete" button 
    },50); 
} 
+0

ありがとうございました。あなたの答えに基づいて質問を更新しました – Andrus

+1

@Andrus:jqGridのナビゲータバーを使用する場合は、[navGrid](http://www.trirand.com/jqgridwiki/doku)の 'prmDel'パラメータとして' myDelOptions'を使うことができます.php?id = wiki:ナビゲータ#定義)。ローカルのフォーム編集を実装するコードを投稿し、[対応する提案]を投稿しました(http://www.trirand.com/blog/?page_id=393/bugs/small-bug-in-generating-new-id-in -postit-of-editgridrow /#p22393)をトリランドフォーラムに追加します。私はもっ​​とはできない。次に、 'multiselect:true'の使い方について書いてきました。それは**絶対に新しい要件です**。 jqGridはグリッド編集でmustiselectを指向しません。 – Oleg

+0

ありがとうございます。最初の質問に投稿されたオプションは 'multiselect:true'でした。 jQgrid標準削除ボタンは選択された行をすべて削除しますが、ローカル置換は1行だけ削除します。 – Andrus