2011-06-02 103 views
0

jQgrid行是使用內聯編輯模式編輯的。 按Enter使用http POST將數據發送到服務器。 POST方法返回狀態400錯誤的請求,如果有一些錯誤。下面的代碼中的errorofunc在此 的情況下顯示錯誤。 用戶更正行中的數據,然後再次按下。jqGrid內聯編輯:如果發佈返回錯誤,如何再次保存

按回車被忽略,沒有任何反應。如果返回404錯誤,它看起來像回車鍵沒有綁定。 編輯行中的更改丟失,無法保存。

我試圖設置在errorfunc中

restoreAfterError = false; grid.restoreAfterErorr = false;

但錯誤後仍無法保存行。

如何允許在返回400錯誤後保存正確的行數據?

<script type="text/javascript"> 
var lastSelectedRow; 
$(function() { 
      var grid = $("#grid"); 
      grid.jqGrid({ 
       url: '/Grid/GetData', 
       datatype: "json", 
       mtype: 'POST', 
       scroll: 1, 
       multiselect: true, 
       multiboxonly: true, 
       scrollingRows : true, 
       autoencode: true, 
       colModel: [ 
     { name: 'Source', fixed: true, editable: true, width: 30 }, 
     { name: 'Est', fixed: true, editable: true, width: 271 }, 
     { name: 'Istopic', fixed: true, editable: true, width: 57 }, 
     {name: 'Critical', fixed: true, editable: true, width: 50} 
    ], 

       gridview: true, 
       pager: '#pager', 
       sortname: 'est', 
       viewrecords: true, 
       rowNum: 30, 
       sortorder: "asc", 
       editurl: '/Grid/Edit' 
      }); 

      $("#grid").jqGrid('bindKeys', { 
       onEnter: function(rowid) { 
        doeditRow(rowid); 
       } 
      } ); 

     }); 

     function doeditRow(rowID) { 
      var grid2 = $("#grid"); 
      if (rowID && rowID !== lastSelectedRow) { 
       grid2.jqGrid('restoreRow', lastSelectedRow); 
       lastSelectedRow = rowID; 
      } 
      invokeEditRow(); 
     } 

     function errorfunc(rowID, response) { 
      // todo: why this does not allow Enter key to continue ase after error: 
      restoreAfterError = false; 
      $("#grid").restoreAfterErorr = false; 
      alert(response.responseText); 
      lastSelectedRow = rowID; 
      invokeEditRow(); 
      return true; 
     } 


     function invokeEditRow() { 
      $("#grid").jqGrid('editRow', lastSelectedRow ,true,null, null, null, {}, 
       null, 
       errorfunc 
      ); 
     } 
    </script> 

<div id="grid1container" style="width: 100%;"> 
    <table id="grid"> 
    </table> 
    <div id="pager"> 
    </div> 
</div> 

UPDATE:errrofunc調用editrow這 根據 https://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js 應該設置再次輸入鍵保存。 由於不明原因,這不會發生 。

更新:在errorfunc網格。根據奧列格註釋改爲

 $("#grid").restoreAfterErorr = false; 

回答

1

可以使用可變griderrorfunc實現(grid.restoreAfterErorr)內。 gridundefined,你有排除異常。

修訂:歐應更換alert(response.responseText);

$.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ 
    response.responseText +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'}); 

看到同樣風格的對話框,在標準情況下。內聯編輯中的errorfunc負責顯示錯誤消息本身。

+0

@Oleg:謝謝。我通過將'grid'更改爲'$(「#grid」)'來更新測試用例。問題依然存在。爲了測試這個,你可以使用我發給你的私人測試網址。首先輸入30個以上的字符(Allikas)列並按回車。出現錯誤消息。編輯Allikas列以少於30個字符並再次按Enter鍵。此輸入按下將被忽略,數據不會被保存。錯誤後如何保存數據?順便說一句。對於未知的理由,即使網格。被使用,在網格中不會發生異常。線。數據庫出現錯誤的適當警報框仍然出現。 – Andrus 2011-06-03 07:04:02

+0

@安德魯斯:你可以將'jquery.jqGrid.min.js'替換爲'jquery.jqGrid.src.js'嗎? – Oleg 2011-06-03 07:26:22

+0

@安德魯斯:我似乎開始明白你的網站有什麼問題。你太頻繁地進入編輯模式。例如在'errorfunc'裏面你不應該調用'invokeEditRow'。此外,似乎如果按Enter鍵保存該行,則不僅保存該行,而且還會接收'keypress'事件以開始內聯編輯(請參閱'bindKeys'),這會對非常陌生的行爲產生影響。 – Oleg 2011-06-03 07:51:32