jqGrid的删除:没有得到价值 [英] jqgrid delete: not getting value

查看:390
本文介绍了jqGrid的删除:没有得到价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发使用JSP和放大器的Web应用程序; Servlet的(IDE:Eclipse中,数据库:ORACLE10)。

I developing a web application using JSP & Servlet (IDE: Eclipse, Database: Oracle10).

我使用 jqGrid的显示在表格格式的数据。我也想添加的功能,编辑,删除 jqGrid的。到目前为止,我已经完成了编辑的功能。

I am using JQGRID to display data in tabular format. I also want functionality of Add, Edit, Delete in JQGRID. So far I have completed Edit Functionality.

现在我想删除的功能,问题是,我不能够从jqGrid的数据传递与Servlet

Now I want Delete functionality, the problem is that I am not able to pass data from JQGRID to servlet.

以下是我的源$ C ​​$ C:

Following is my source code:

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);
            });

我收到 protID 未定义在我的 DeleteServlet

推荐答案

您使用 protID 网​​址的走错了路。 网​​址选项用于删除操作的值将被设置在执行的呼叫 navGrid 。此刻的你还没有设置任何的变量值 protID 。您可以修复的code您可以使用一个由以下几种方式: onclickSubmit delData beforeSubmit serializeDelData

You use protID in the url in the wrong way. The value of url option used for Delete operation will be set once during executing of the call of navGrid. At the moment you not yet set any value for the variable protID. You can fix the code you can use one from the following ways: onclickSubmit, delData, beforeSubmit or serializeDelData.

我wounder一点,你使用 MTYPE:GET选项删除操作。通常一次使用HTTP POST或HTTP DELETE的情况下。如果你真的需要 MTYPE:GET您可以替换

I am wounder a little that you use mtype: 'GET' option for delete operation. Typically one use HTTP POST or HTTP DELETE in the case. If you really need mtype: 'GET' you can replace

{
    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 等为 GET ,但需要设置 protID 作为URL的一部分,可以动态修改网​​址选项 onclickSubmit 或 beforeSubmit 回调。例如

If you do consider to use mtype other as GET, but will need to set protID as part of URL you can modify url option dynamically inside of onclickSubmit or beforeSubmit callback. For example

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

您可以选择自己能够更好地符合您的需求的方式。

You can choose yourself the way which better corresponds your requirements.

这篇关于jqGrid的删除:没有得到价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆