在我的情況下,我需要允許用戶編輯網格中的各種單元格,然後將整個網格保存到服務器。我已經使用內聯編輯和保存到'clientArray'來解決這個問題。但是,我試圖使用editRules並遇到一些問題。jqGrid - 內聯編輯和陷印編輯規則
如果我使列可編輯,並使用編輯規則來要求它是一個數字
{ name: 'Value', index: 'Value', width: 50, sortable: true,edittype: 'text',
editable: true, editoptions: { maxlength: 10 },
editrules:{number: true},
formatter:currencyFmatter, unformat:unformatCurrency },
,我控制編輯和保存在onSelectRow
事件:
onSelectRow: function(id){
if(id && id!==lastSel){
jQuery("#Groups").saveRow(lastSel,true,'clientArray');
jQuery("#Groups").editRow(id,true);
}
lastSel=id
},
然後我用一個按鈕點擊事件來保存網格。一切都很好,直到我將一個非數字值放入值單元格中,然後單擊它下面的行。它拋出警告框並停止保存,但它不會阻止我更改行。所以我現在有兩行打開進行編輯。有沒有辦法來捕捉editrule錯誤,所以我可以在移動到下一行之前處理它。
我試圖用saveRow(succesfunc,aftersavefunc,errorfunc,afterrestorefunc)來使用函數,其中所有的數據在數據保存到服務器後都會觸發,這似乎不適用於'clientArray'。
基本上,我需要找到一種方法來驗證保存到'clientArray'時的內聯編輯中的數據,並且信息,建議,特別是示例將不勝感激。
謝謝。
玩了一段時間後,我決定編輯規則不用在inLine編輯中工作得很好。所以,如你所說,我做了我自己的驗證程序。訣竅是弄清楚如何獲得編輯行的值。
我現在想弄明白的一件事是如何讓焦點返回到Value列。回到文檔!
if(id && id!==lastSel){
//dont save if first click
if (lastSel != -1) {
//get val of Value to check
var chkval = jQuery("#"+lastSel+"_Value").val() ;
// verify it is a number
if (isNaN(chkval)) {//If not a number
//Send Validation message here
//Restore saved row
jQuery("#Grid").restoreRow(lastSel);
//Return to failed save row
jQuery("#Grid ").setSelection(lastSel,false);
//reopen for editing
jQuery("#Grid ").editRow(lastSel,true);
//Note - dont reset lastSel as you want to stay here }
else {
// If number is good, proceed to save and edit next
jQuery("#Grid ").jqGrid('saveRow',lastSel, checksave, 'clientArray', {}, null, myerrorfunc);
jQuery("#Grid ").editRow(id,true);
lastSel=id;
};
isDirty = true;
};
else {
//first click - open row for editing
alert("new Edit")
jQuery("#Grid ").editRow(id,true);
lastSel=id;}
}
謝謝,賈斯汀使用的「saveRow」。請標記內置的返回類型的答案。我試圖沿着這條路走,但不知道如何從行中獲取數據。我嘗試了jQuery(「#rowid_myCol」)。Val()來獲取我的值的值,但這不起作用。如何獲得Value的價值,以便我可以測試它。 --DW –
好的,您實際上需要先調用saveRow(),以便您可以正確訪問行數據。我應該在上面闡明。然後你可以使用getRowData()來獲取行的數據。這有幫助嗎? –
如果我調用saveRow()如果失敗了editrule並且不會被保存。我想我很接近。我相信我需要使用jQuery(#lastSel_myCol「)。val()。我碰到了錯誤的行,如果我把它正確的話,我會發布它 –