jqGrid 4.13.6-pre - free jqGrid
我正在使用navGrid和內聯編輯,並且在從服務器發送回格式驗證消息時遇到問題。驗證消息在從內聯編輯返回時顯示正常,但在從網格導航訪問的「添加/編輯」表單上顯示時,它們看起來不太好。JqGrid,如何使用navGrid時格式錯誤消息
我讀了很多關於errorTextFormat事件,它似乎正是我想要的,但我似乎無法弄清楚如何從grid nav打開表單時訪問它。我確信有一個簡單的方法來配置它,但我一直無法弄清楚。
$(function() {
var lastSel = 0;
$("#Grid")
.jqGrid({
url: '/url/to/griddata',
datatype: 'json',
mtype: 'POST',
colNames: ['Id', 'Name'],
colModel: [
{ name: 'Id', hidden: false, search: true, width: 150, align: 'center', sortable: true, editable: false, formatter: null, edittype: 'text' },
{ name: 'Name', hidden: false, search: true, width: 150, align: 'center', sortable: true, editable: true, formatter: null, edittype: 'text', editoptions: { maxlength: 256, value: null, required: true } }],
pager: '#GridPager',
prmNames: {
page: 'PageNumber',
rows: 'PageSize',
sort: 'SortColumn',
order: 'SortOrder',
search: 'Search',
nd: 'nd',
npage: 'null'
},
rowNum: 60,
rowList: [
15,
30,
60,
120
],
sortname: "Name",
sortorder: "asc",
viewrecords: true,
hidegrid: false,
gridview: true,
caption: '',
width: 980,
height: 100,
editurl: '/my/edit/url',
edit: {
errorTextFormat: function (data) {
alert('fired');
console.log(data);
return "error here";
}
},
jsonReader: {
total: 'TotalPages',
page: 'CurrentPage',
records: 'TotalRecords',
root: 'Rows',
id: 'Id',
repeatitems: false
},
onSelectRow: function(id) {
if (id && id !== lastSel) {
jQuery('#Grid').restoreRow(lastSel);
lastSel = id;
}
$('#Grid').jqGrid('editRow', id,
{
keys: true
});
}
});
$("#Grid").filterToolbar({ autosearch: true, searchOnEnter: false });
$("#Grid").navGrid('#GridPager', {
del: false, search: false, editerrorTextFormat: function (data) {
alert('fired');
console.log(data);
return "error here";
}
});
這裏是標記。
請包含代碼片段,它顯示了您如何嘗試使用表單編輯和回調'errorTextFormat'。典型錯誤:將回調包括在錯誤的地方。您還應該總是包含關於您使用(或可以使用)的jqGrid的版本和分支的信息。有兩個主要的叉子:[免費jqGrid](https://github.com/free-jqgrid/jqGrid),商業[Guriddo jqGrid JS](http://guriddo.net/?page_id=103334)和一箇舊的jqGrid在<= 4.7的版本中。在jqGrid中有*不同的*可能性來指定'errorTextFormat'。 – Oleg
如果您搜索使用的例子'errorTextFormat'你可以找到更多信息[這裏](http://stackoverflow.com/a/6803206/315935)和[這裏](http://stackoverflow.com/a/14864422/315935)。如果沒有幫助,那麼你應該追加與JavaScript代碼和服務器響應的例子你的問題,包括在HTTP代碼,您可以使用從服務器返回驗證錯誤。該響應可以在IE /鉻/火狐(網絡選項卡)的開發工具或[提琴手](http://www.telerik.com/fiddler)中可以看出。 – Oleg
我添加的JavaScript /標記的問題。 – James