Jqgrid 在点击按钮之前,我想检查是否有任何验证剂量火灾
我启用了JQGrid,并启用了就地编辑。 数据库字段 姓名(必填) 姓氏(非必需) 以下是场景:Jqgrid 在点击按钮之前,我想检查是否有任何验证剂量火灾,jqgrid,Jqgrid,我启用了JQGrid,并启用了就地编辑。 数据库字段 姓名(必填) 姓氏(非必需) 以下是场景: jQuery(document).ready(function () { //$.jgrid.defaults.loadtext = ''; jQuery("#list").jqGrid({ url: '@Url.Action("JQGridGetGridData", "TabMaster")', datatype: '
jQuery(document).ready(function () {
//$.jgrid.defaults.loadtext = '';
jQuery("#list").jqGrid({
url: '@Url.Action("JQGridGetGridData", "TabMaster")',
datatype: 'json',
mtype: 'GET',
colNames: ['col ID', 'First Name', 'Last Name', ''],
colModel: [
{ name: 'colID', index: 'colID', width: 100, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
{ name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true, editrules: { required: true, number: true, minValue: 40, maxValue: 100} },
{ name: 'LastName', index: 'LastName', width: 150, align: 'left', editable: true },
{ name: 'Edit', index: 'Edit', width: 70, align: 'center', editable: false, formatter: editFmatter, unformat: unformatEdit }
],
pager: jQuery('#pager'),
hidegrid: false,
rowNum: 100,
rowList: [10, 50, 100, 150],
sortname: 'colID',
sortorder: "asc",
viewrecords: true,
multiselect: false,
//rownumbers: true,
imgpath: '@Url.Content("~/Scripts/themes/steel/images")',
caption: 'Tab Master Information',
editurl: '@Url.Action("JQGridEdit", "TabMaster")'
}).navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: false });
});
function inplaceEdit(id) {
jQuery('#list').editRow(id);
changeActionState('edit', id);
}
function inplaceCancel(id) {
jQuery('#list').restoreRow(id);
changeActionState('cancel', id);
}
function inplaceSave(id) {
jQuery('#list').saveRow(id);
changeActionState('save', id);
}
function changeActionState(action, id) {
if (action == 'edit') {
jQuery('#action_edit_' + id).css('display', 'none');
jQuery('#action_delete_' + id).css('display', 'none');
jQuery('#action_save_' + id).css('display', 'block');
jQuery('#action_cancel_' + id).css('display', 'block');
}
else {
jQuery('#action_edit_' + id).css('display', 'block');
jQuery('#action_delete_' + id).css('display', 'block');
jQuery('#action_save_' + id).css('display', 'none');
jQuery('#action_cancel_' + id).css('display', 'none');
}
}
1.带有编辑和删除按钮的网格。2.单击编辑,然后(编辑、删除将隐藏)和(保存、取消将显示)。
3。我已清除FirstName文本框中的值。
4.我按下了提交按钮,然后它将显示类似“名字:需要字段”的消息这是正确的
5.但在我的按钮后面(保存、取消将替换为编辑,删除这是错误的) 我想在以下函数中设置检查点
function inplaceSave(id) {
//Check point is required for Any Validation violation or unsuccessful save
jQuery('#list').saveRow(id);
//if it is success then following method should called else couldn't
changeActionState('save', id);
}
以下是代码:
jQuery(document).ready(function () {
//$.jgrid.defaults.loadtext = '';
jQuery("#list").jqGrid({
url: '@Url.Action("JQGridGetGridData", "TabMaster")',
datatype: 'json',
mtype: 'GET',
colNames: ['col ID', 'First Name', 'Last Name', ''],
colModel: [
{ name: 'colID', index: 'colID', width: 100, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
{ name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true, editrules: { required: true, number: true, minValue: 40, maxValue: 100} },
{ name: 'LastName', index: 'LastName', width: 150, align: 'left', editable: true },
{ name: 'Edit', index: 'Edit', width: 70, align: 'center', editable: false, formatter: editFmatter, unformat: unformatEdit }
],
pager: jQuery('#pager'),
hidegrid: false,
rowNum: 100,
rowList: [10, 50, 100, 150],
sortname: 'colID',
sortorder: "asc",
viewrecords: true,
multiselect: false,
//rownumbers: true,
imgpath: '@Url.Content("~/Scripts/themes/steel/images")',
caption: 'Tab Master Information',
editurl: '@Url.Action("JQGridEdit", "TabMaster")'
}).navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: false });
});
function inplaceEdit(id) {
jQuery('#list').editRow(id);
changeActionState('edit', id);
}
function inplaceCancel(id) {
jQuery('#list').restoreRow(id);
changeActionState('cancel', id);
}
function inplaceSave(id) {
jQuery('#list').saveRow(id);
changeActionState('save', id);
}
function changeActionState(action, id) {
if (action == 'edit') {
jQuery('#action_edit_' + id).css('display', 'none');
jQuery('#action_delete_' + id).css('display', 'none');
jQuery('#action_save_' + id).css('display', 'block');
jQuery('#action_cancel_' + id).css('display', 'block');
}
else {
jQuery('#action_edit_' + id).css('display', 'block');
jQuery('#action_delete_' + id).css('display', 'block');
jQuery('#action_save_' + id).css('display', 'none');
jQuery('#action_cancel_' + id).css('display', 'none');
}
}
像这样的内联编辑(非就地编辑)方法有多个参数。附加参数允许您在数据验证或数据保存成功与否的情况下执行不同的操作
您使用哪个版本的jqGrid?为什么继续使用诸如imgpath
之类的参数?为什么不使用格式化程序:“操作”?它似乎正是你所需要的。此外,您的代码不清楚如何以及何时调用inplaceSave
此外,您在中发布的作为解决方案的
editFmatter
代码似乎是错误的。它可以用于从服务器发送的Edit
列的某些空间内容,这些内容未包含在问题文本中。单元格中有公共文本作为输入。代码函数editFmatter(el,cellval,opts){…;$(el).html(finalHTML)
中的表达式$(el)
没有意义。自定义格式设置程序的参数是(cellvalue,options,rowObject)
。您可能希望使用而不是自定义格式,但应该以另一种方式使用:edittype:'custom',editoptions:{custom\u元素:editFmatter,
我自己解决了这个问题,使用了修改后的函数inplaceSave并添加了新函数checkSave
这是更新后的代码
谢谢,伊姆达杜森