【问题标题】:jqgrid delete: not getting valuejqgrid删除:没有得到价值
【发布时间】:2012-12-21 01:48:37
【问题描述】:

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

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

现在我想要Delete 功能,问题是我无法pass data from JQGRID to servlet

以下是我的源代码:

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;
                        alert(protID);
                        stageID = ret.STAGE_ID;
                        alert(stageID);

                        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;
                    }
                }
            });
            jQuery("#list10_d2").jqGrid('navGrid','#pager10_d2',{add:true,edit:true,del:true},{width:500},{width:500,url: 'ProtocolJGridServChildStages?action=protocolStageAdd&protID='+protID, closeAfterAdd: true},{mtype: 'GET',url: 'ProtocolJGridServChildStages?action=protocolStageDelete&protID='+protID});
            jQuery("#ms1").click( function() {
                var s;
                s = jQuery("#list10_d2").jqGrid('getGridParam','selarrrow');
                alert(s);
            });

我在我的DeleteServlet 中得到protIDundefined

【问题讨论】:

    标签: jquery ajax jsp servlets jqgrid


    【解决方案1】:

    您以错误的方式在url 中使用protID。用于删除操作的url 选项的值将在执行navGrid 的调用期间设置一次。目前您还没有为变量protID 设置任何值。您可以通过以下方式修复可以使用的代码:onclickSubmitdelDatabeforeSubmitserializeDelData

    您使用mtype: 'GET' 选项进行删除操作让我有点担心。在这种情况下,通常使用 HTTP POST 或 HTTP DELETE。如果你真的需要mtype: 'GET'你可以替换

    {
        mtype: 'GET',
        url: 'ProtocolJGridServChildStages?action=protocolStageDelete&protID=' + protID
    }
    

    navGrid的参数

    {
        mtype: 'GET',
        url: 'ProtocolJGridServChildStages',
        delData: {
            action: 'protocolStageDelete',
            protID: function () {
                return protID;
            }
        }
    }
    

    或者

    {
        mtype: 'GET',
        url: 'ProtocolJGridServChildStages',
        onclickSubmit: function (options, rowid) {
            var rowData = jQuery(this).jqGrid('getRowData', rowid);
            return {
                action: 'protocolStageDelete',
                protID: ret.PROTOCOL_ID
            };
        }
    }
    

    如果您确实考虑使用mtype other 作为GET,但需要将protID 设置为URL 的一部分,您可以在onclickSubmitbeforeSubmit 回调中动态修改url 选项。例如

    {
        mtype: 'GET',
        onclickSubmit: function (options, rowid) {
            var rowData = jQuery(this).jqGrid('getRowData', rowid);
            options.url = 'ProtocolJGridServChildStages?' + jQuery.param({
                action: 'protocolStageDelete',
                protID: ret.PROTOCOL_ID
            });
        }
    }
    

    您可以选择更符合您要求的方式。

    【讨论】:

    • 感谢您解释替代方案。
    猜你喜欢
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    相关资源
    最近更新 更多