Java jqGrid:更新和插入数据时显示/隐藏列

Java jqGrid:更新和插入数据时显示/隐藏列,java,javascript,jsp,servlets,jqgrid,Java,Javascript,Jsp,Servlets,Jqgrid,我正在使用JSP和Servlet(IDE:Eclipse,数据库:Oracle10)开发一个web应用程序。我使用jqGrid以表格格式显示记录 代码片段: jQuery("#list10").jqGrid({ url:'ProfileServ?action=profile', datatype: "xml", sortable: true, height: 250, width: 550, colN

我正在使用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列中是
隐藏的,因为我不希望它们以表格格式显示。当用户希望
插入
更新
数据时,我想显示这些列

因此,在我的代码中,我将这些列属性设置为
cm.hidden=false在ShowForm
事件之前打开。但问题是,当用户想要编辑数据时,他必须在编辑按钮上单击两次,第一次单击时仅显示两列,它们在
colModel
中未隐藏,当用户在编辑按钮上单击两次时,则显示我设置的字段
cm.hidden=false将显示。插入数据时也会发生同样的情况

我想我把
recreateForm:true
放在了错误的地方或错误的事件中


提前感谢。

只需将隐藏行设置为具有以下属性:

editable:true, editrules: {edithidden:true}},
JSFIDLE示例