【问题标题】:Sending additional parameters to editurl on JQgrid向 JQgrid 上的 editurl 发送附加参数
【发布时间】:2011-03-11 17:00:09
【问题描述】:

我现在的问题是在编辑该行时尝试发送该行的 ID (editable: false)。

例如,我有一个包含 userid(editable: false)、userid(editable: true)、firstname(editable: true)、lastname(editable: true) 列的网格。编辑行时,网格仅发送参数用户名、名字和姓氏。在服务器端,我需要用户 ID 来知道我已将这些新值应用到哪个用户。

editUrl 看起来像:

editurl : CONTEXT_PATH+'/ajax/admin/savePart.do?category=1',

谢谢

这是完整的代码:

$.jgrid.useJSON = true;
//http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3Acommon_rules
$(document).ready(function() {
    //alert(CONTEXT_PATH);
    var lastsel;
    jQuery("#rowed3").jqGrid(
            {
                url : CONTEXT_PATH+'/ajax/getPartesByCategory.do?catid=<s:property value="categoryId" />',
                //url : '/autoWEB/text.html',
                datatype: "json",
                ajaxGridOptions: { contentType: "application/json" },
                jsonReader : { 
                    root: "rows", 
                    page: "page", 
                    total: "total", 
                    records: "records", 
                    repeatitems: false 
                },
                headertitles: true,
                colNames : [ 'ID', 'Pieza', 'Disponible'],
                colModel : [ {
                    name : 'piezaId',
                    index : 'piezaId',
                    align : "right",
                    width : 50, 
                    editable : false,
                    required : true
                }, {
                    name : 'descripcion',
                    index : 'descripcion',
                    width : 390,
                    editable : true,
                    required : true
                }, {
                    name : 'disponible',
                    index : 'disponible',
                    width : 80,
                    editable : true,
                    edittype : 'select',
                    editoptions:{value:"0:No;1:Si"},
                    required : true
                } ],
                rowNum : 20,
                rowList : [ 20, 40, 60, 80 ],
                pager : '#prowed3',
                sortname : 'piezaId',
                postData: {piezaId : lastsel},
                mtype:"POST",
                viewrecords : true,
                sortorder : "desc",
                onSelectRow : function(id) {
                    if (id && id !== lastsel) {
                        jQuery('#rowed3').jqGrid('restoreRow', lastsel);
                        jQuery('#rowed3').jqGrid('editRow', id, true);
                        lastsel = id;
                    }
                },
                editurl : CONTEXT_PATH+'/ajax/admin/savePieza.do?categoria=<s:property value="categoryId" />',
                caption : "Piezas"
            });
    jQuery("#rowed3").jqGrid('navGrid', "#prowed3", {
        edit : false,
        add : false,
        del : false
    });
})

【问题讨论】:

    标签: javascript jquery ajax datagrid jqgrid


    【解决方案1】:

    在您的 onSelectRow 回调中,您可以将 editUrl 修改为您想要的任何内容,包括传入您需要的 ID。

    $("#rowed3").jqGrid('setGridParam', {editurl:'whatever/url/you/need/with/the/id'});
    

    jqGrid 将为您添加所有其他必要的参数到该 editurl。

    【讨论】:

      【解决方案2】:

      你可以使用

      hidden: true, editable: true, editrules: { edithidden: false }, hidedlg: true
      

      piezaId (ID) 列的定义中。 hidedlg 参数目前不是真正需要的,但如果您决定使用其他 jqGrid 功能,它会很有用。

      【讨论】:

      【解决方案3】:

      在 GET 字符串中传递值对我有用。

      editurl: '/ajax/update?line=1',
      

      【讨论】:

        猜你喜欢
        • 2011-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-22
        • 2015-07-14
        相关资源
        最近更新 更多