我有一个使用表单编辑的 jqGrid。我希望某些字段在“编辑”模式下是只读的,而不是在“添加”模式下。我已经尝试了一些我在其他地方找到的建议来解决这个问题(见下面的例子),但仍然无法让它工作!
如果有人可以提供帮助,我将不胜感激!
在下面的网格中,我试图在“编辑”模式下将“登录名”设置为只读,而不是在“添加”模式下。
$('#jpgCustomers').jqGrid({
url: '@Url.Action("Customers")',
datatype: 'json',
mtype: 'POST',
colNames: ['Name', 'FullName', 'Description'],
colModel: [
{ name: 'LogonName', index: 'LogonName', align: 'left', width:80, editable:true, search:true, stype:'text',editrules:{required:true}},
{ name: 'FullName', index: 'FullName', align: 'left',width: 200, editable:true, search:true, stype:'text',editrules:{required:true}},
{ name: 'Description', index: 'Description', align: 'left', width: 300, editable:true, search:true, stype:'text'}
]
//..
$("#jpgCustomers").jqGrid('navGrid', '#jpgpCustomers',
{ add: true, del: true, edit: true, search: false},
//edit form
{ width: '500',
editCaption: 'Edit Customer',
url: '@Url.Action("EditCustomer")',
reloadAfterSubmit: true,
closeAfterEdit: true,
//always start from a new form
recreateForm: true,
beforeShowForm: function(form) {
//center the edit dialog on screen
var dlgDiv = $("#editmod" + jpgCustomers.id);
CenterDialog(dlgDiv);
$("#jpgCustomers").jqGrid('setColProp','LogonName',{editoptions: {readonly:'readonly'}});
}
},
//Add form
{ width: '500',
addCaption: 'Add Customer',
url: '@Url.Action("CreateCustomer")',
reloadAfterSubmit: true,
closeAfterEdit: true,
beforeShowForm: function(form) {
var dlgDiv = $("#editmod" + jpgCustomers.id);
CenterDialog(dlgDiv);
$("#jpgCustomers").jqGrid('setColProp','LogonName',{editoptions: {readonly:false}});
}
},
//Delete form
{ width: '250',
url: '@Url.Action("DeleteCustomer")',
beforeShowForm: function(form) {
//center the delete dialog on screen
var dlgDiv = $("#delmod" + jpgCustomers.id);
CenterDialog(dlgDiv);
//change the Delete confirmation message
var sel_id = $("#jpgCustomers").jqGrid('getGridParam','selrow')
$("td.delmsg", form).html("Delete User <b>" + $("#jpgCustomers").jqGrid('getCell', sel_id,'LogonName') + "</b>?");
}
}
);