java - jqgrid:添加行

标签 java jsp servlets jqgrid

我正在使用 JSP 和 Servlet 开发 Web 应用程序(IDE:Eclipse,数据库:Oracle10)。

我正在使用 JQGRID 以表格格式显示数据。我还想要 JQGRID 中的添加、编辑、删除功能。到目前为止我已经完成了编辑、删除功能。

现在我想要添加功能,问题是当我单击默认的Add按钮时,它只向我显示设置为可编辑的DESCRIPTION字段: true 并且不显示其他两个不可编辑的字段。我没有将它们设置为可编辑,因为它们是主键,并且我不希望它们被编辑。

所以我的问题是,有什么方法可以在用户单击“添加”后将不可编辑的列设置为“可编辑”。

以下是我的源代码:

jQuery("#list10_d2").jqGrid({
                height: "100%",
                url:'ProtocolJGridServChildStages?q=2&action=protStages',
                datatype: "xml",
                 colNames:['Sr. No.','PROTOCOL_ID',  'STAGE_ID',  'DESCRIPTION'],
                 colModel:[{name:'srNo',index:'srNo', width:35,sortable:true},
                           {name:'PROTOCOL_ID',index:'PROTOCOL_ID', width:100,sortable:false},
                           {name:'STAGE_ID',index:'STAGE_ID', width:100,sortable:false},
                           {name:'DESCRIPTION',index:'DESCRIPTION', width:150,sortable:false,editable:true}
                           ],
                rowNum:5,
                rowList:[2,4,10],
                pager: '#pager10_d2',
                sortname: 'PROTOCOL_ID',
                viewrecords: true,
                sortorder: "asc",
                multiselect: true,
                editurl: "ProtocolJGridServChildStages?action=protocolStageEdit",
                caption:"CRM_PROT_STAGES",
                onSelectRow: function(ids)
                {
                    if(ids && ids!==lastsel)
                    {               
                        var ret = jQuery("#list10_d2").jqGrid('getRowData',ids);
                        protID = ret.PROTOCOL_ID;
                        stageID = ret.STAGE_ID;

                        jQuery("#list10_d2").jqGrid('setGridParam',{editurl:'ProtocolJGridServChildStages?action=protocolStageEdit&protID='+protID+'&stageID='+stageID});
                        jQuery('#list10_d2').jqGrid('restoreRow',lastsel);
                        jQuery('#list10_d2').jqGrid('editRow',ids,true);
                        lastsel=ids;
                    }
                }
            }).navGrid('#pager10_d2',{add:true,edit:true,del:true},{width:400,height:200},{width:500,mtype:'POST', url: 'ProtocolJGridServChildStages', addData:{action:'protocolStageAdd',protID: function () {return protID;}, stageID: function(){return stageID;}}, closeOnSubmit: true},{mtype: 'POST',url: 'ProtocolJGridServChildStages',delData: {action: 'protocolStageDelete',protID: function () {return protID;}, stageID: function(){return stageID;}}});
            jQuery("#ms1").click( function() {
                var s;
                s = jQuery("#list10_d2").jqGrid('getGridParam','selarrrow');
                alert(s);
            }).navGrid('#page',{edit:true,add:true,del:true});

提前致谢...

编辑:

.navGrid('#pager10_d2',{add:true,edit:true,del:true},{width:400,height:200},{width:500,mtype:'POST', url: 'ProtocolJGridServChildStages',beforeShowForm: function(){var cm = $('#list10_d2').jqGrid('getColProp',"PROTOCOL_ID");  cm.editable=true; cm = $('#list10_d2').jqGrid('getColProp',"STAGE_ID");  cm.editable=true; alert("before");}, addData:{action:'protocolStageAdd',protID: function () {return protID;}, stageID: function(){return stageID;}}, closeOnSubmit: true},{mtype: 'POST',url: 'ProtocolJGridServChildStages',delData: {action: 'protocolStageDelete',protID: function () {return protID;}, stageID: function(){return stageID;}}});

编辑

    }).navGrid('#pager10_d2',{add:true,edit:true,del:true},
                    {closeOnEscape:true, recreateForm: true, width:400,height:200},
                    {closeOnEscape:true, recreateForm: true, beforeShowForm: function(formId){var cm = $('#list10_d2').jqGrid('getColProp',"PROTOCOL_ID");  cm.editable=false; var cm2 = $('#list10_d2').jqGrid('getColProp',"STAGE_ID");  cm2.editable=true; alert("before");}, addData:{action:'protocolStageAdd',protID: function () {return protID;}, stageID: function(){return stageID;}},width:500,mtype:'POST', url: 'ProtocolJGridServChildStages',closeOnSubmit: true},
                    {closeOnEscape:true, recreateForm: true, mtype: 'POST',url: 'ProtocolJGridServChildStages',delData: {action: 'protocolStageDelete',protID: function () {return protID;}, stageID: function(){return stageID;}}});

最佳答案

试试这个

在beforeShowForm事件中

添加此代码

var cm = $('#list10_d2').jqGrid('getColProp',"PROTOCOL_ID");

里面添加选项

  {   cm.editable=true;}

里面添加选项

 {cm.editable=false; }

关于java - jqgrid:添加行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14211889/

相关文章:

java - 将整数输入数组时出错?

java - 为什么添加一个空的 for 循环可以修复此代码?

java中spring的bean作用域和生命周期

java - doGet() 如何支持书签?

java - 各种 Web 服务器的 servlet/jsp 规范

java - 如何通过内部映射中的参数查找 mongo 文档(最好使用 Spring MongoTemplate)

java - 使用 @Component 继承抽象类 (NoUniqueBeanDefinitionException)

javascript - 如果用户在 jsp 中填写一个字段(同时使用 spring mvc 和 hibernate),我如何自动填写其他表单字段

javascript - 如何使用输入值 Angular Json 填充表?

java - 在jsp页面中做request.setAttribute,在java代码中做request.getAttribute