【发布时间】:2017-04-08 03:57:19
【问题描述】:
jqGrid 4.13.6-pre - free jqGrid
我正在使用 navGrid 和内联编辑,但在格式化从服务器发回的验证消息时遇到问题。验证消息从内联编辑返回时看起来不错,但在从网格导航访问的“添加/编辑”表单上看起来不太好。
我阅读了很多关于 errorTextFormat 事件的内容,它似乎完全符合我的要求,但是当从网格导航打开表单时,我似乎无法弄清楚如何访问它。我确信有一个简单的方法来配置它,但我一直无法弄清楚。
$(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 的版本和分支的信息。有两个主要分支:free jqGrid、商业Guriddo jqGrid JS 和版本 errorTextFormat 有 不同的 种可能性。 -
我在问题中添加了 javascript/标记。
-
添加 jqgrid 版本。
-
我已经看到了与 errorTextFormat 相关的这两个答案。尽管在使用 navGrid 时,我找不到任何将其实际放置在配置代码中的示例。
标签: jquery jqgrid jqgrid-formatter