我正在使用 JSP 和 Servlet(IDE:Eclipse,数据库:Oracle10)开发一个 Web 应用程序。我正在使用 jqGrid 以表格格式显示记录。
代码片段:
jQuery("#list10").jqGrid({
url:'ProfileServ?action=profile',
datatype: "xml",
sortable: true,
height: 250,
width: 550,
colNames:['Sr.No.','PROFILE_ID','PROFILE_NAME','TITLE','FIRST_NAME','MIDDLE_NAME','LAST_NAME'],
colModel:[{name:'srNo',index:'srNo', width:20,sortable:true, hidden:true},
{name:'PROFILE_ID',index:'PROFILE_ID', width:70,sortable:true,editable:true},
{name:'PROFILE_NAME',index:'PROFILE_NAME', width:150,sortable:true,editable:true},
{name:'TITLE',index:'TITLE', width:200,sortable:false,editable:true, hidden:true},
{name:'FIRST_NAME',index:'FIRST_NAME', width:200,sortable:false,editable:true, hidden:true},
{name:'MIDDLE_NAME',index:'MIDDLE_NAME', width:200,sortable:false,editable:true, hidden:true},
{name:'LAST_NAME',index:'LAST_NAME', width:200,sortable:false,editable:true, hidden:true}],
rowNum:10,
rowList:[10,20,50,100],
pager: '#pager10',
sortname: 'srNo',
loadonce:true,
ignoreCase: true,
viewrecords: true,
sortorder: "desc",
multiselect: false,
editurl: "ProfileServ?action=profileEdit",
caption: "Profile",
}).navGrid('#pager10',{edit:true,add:true,del:true,view:true},
{modal:true,checkOnUpdate:true,closeOnEscape:true,width:500,closeOnSubmit: true,editurl:'ProfileServ?action=profileEdit',
beforeShowForm: function(formid){alert('hiu');
cm = $('#list10').jqGrid('getColProp',"PROFILE_NAME"); cm.hidden=true;
cm = $('#list10').jqGrid('getColProp',"TITLE"); cm.hidden=false;
cm = $('#list10').jqGrid('getColProp',"FIRST_NAME"); cm.hidden=false;
cm = $('#list10').jqGrid('getColProp',"MIDDLE_NAME"); cm.hidden=false;
cm = $('#list10').jqGrid('getColProp',"LAST_NAME"); cm.hidden=false;},recreateForm: true},
{modal:true,closeOnEscape:true,recreateForm: true,width:500,mtype:'POST', url: 'ProfileServ',editData:{action: 'profileAdd',profileID: function () {return profileID;}},
beforeShowForm: function(formid){alert('hi');
cm = $('#list10').jqGrid('getColProp',"PROFILE_NAME"); cm.hidden=true;
cm = $('#list10').jqGrid('getColProp',"PROFILE_ID"); cm.editable=true;
cm = $('#list10').jqGrid('getColProp',"TITLE"); cm.hidden=false;
cm = $('#list10').jqGrid('getColProp',"FIRST_NAME"); cm.hidden=false;
cm = $('#list10').jqGrid('getColProp',"MIDDLE_NAME"); cm.hidden=false;
cm = $('#list10').jqGrid('getColProp',"LAST_NAME"); cm.hidden=false;},recreateForm: true},
{closeOnEscape:true, recreateForm: true,mtype: 'POST',url: 'ProfileServ',delData: {action: 'profileDelete',profileID: function () {return profileID;}},closeOnSubmit: true},
{closeOnEscape: true, multipleSearch: true, closeAfterSearch: true,width: 700},
{recreateForm: true,width:700,navkeys: [true,38,40],closeOnEscape:true});
在我的colModel
4 列中是hidden
,因为我不希望它们以表格格式显示。我想在用户想要Insert
或Update
数据时显示这些列。
因此,在我的代码中,我将这些列属性设置为cm.hidden=false;
on beforeShowForm
事件。但问题是,当用户想要编辑数据时,他必须在编辑按钮上单击两次,第一次单击时只显示两列未隐藏的列colModel
,当用户在编辑按钮上单击两次时,我已设置cm.hidden=false;
显示。插入数据时发生同样的事情。
我想我放在recreateForm: true
错误的地方或错误的事件中。
提前致谢。