如何在使用jqGrid“actions”预定义格式化程序时传递额外参数?

时间:2012-06-21 05:52:42

标签: jquery jquery-plugins jqgrid jqgrid-formatter

我正在使用jqGrid v3.8.1并且无法使用预定义的格式化程序“actions”传递额外的参数。基本上我想在编辑和删除时传递两个参数以及编辑过的字段。根据文档,extraparam可用于将其他参数发布到服务器。我尽我所能并尽可能多地研究,但是,我仍然无法让它发挥作用。我已经提到了以下内容:

Link 1
Link 2

以及stackoverflow和其他地方的其他人。我不确定会出现什么问题。

以下是我的代码。请帮帮我。

jQuery("#configGrid").jqGrid({
    mtype: "post",
    url: '/Controller/Action',
    datatype: "json",
    colNames: ['Location', 'S_No', 'S_C', 'D_No', 'D_C', 'B_No', 'B_C', 'G_No', 'GP_P', 'IP', 'OA', 'NA', 'Months', 'Edit'],
    colModel: [{
        name: 'name',
        index: 'name',
        width: 90
    }, {
        name: 's_no',
        index: 's_no',
        width: 90,
        align: "center",
        editable: false
    }, {
        name: 's_c',
        index: 's_c',
        width: 90,
        align: "center",
        editable: true
    }, {
        name: 'd_no',
        index: 'd_no',
        width: 90,
        align: "center",
        editable: false
    }, {
        name: 'd_c',
        index: 'd_c',
        width: 90,
        align: "center",
        editable: true
    }, {
        name: 'b_no',
        index: 'b_no',
        width: 90,
        align: "center",
        editable: false
    }, {
        name: 'b_c',
        index: 'b_c',
        width: 90,
        align: "center",
        editable: true
    }, {
        name: 'g_no',
        index: 'g_no',
        width: 100,
        align: "center",
        editable: false
    }, {
        name: 'g_c',
        index: 'g_c',
        width: 100,
        align: "center",
        editable: true
    }, {
        name: 'TIP',
        index: 'TIP',
        width: 80,
        align: "right",
        editable: true
    }, {
        name: 'OA',
        index: 'OA',
        width: 80,
        align: "center",
        editable: true
    }, {
        name: 'NA',
        index: 'NA',
        width: 80,
        align: "center",
        editable: true
    }, {
        name: 'Months',
        index: 'Months',
        width: 150,
        align: "center",
        sortable: false,
        editable: true
    }, {
        name: 'myac',
        width: 50,
        align: "center",
        fixed: true,
        sortable: false,
        resize: false,
        formatter: 'actions',
        formatoptions: {
            keys: true,
            extraparam: {
                slot: "1",
                installment: "1"
            }
        }
    }],
    rowNum: 10,
    rownumbers: true,
    autowidth: true,
    rowList: [10, 20, 30],
    postData: {
        level: function () {
            if (p_level == undefined || p_level == null) {
                return 'S';
            } else {
                return p_level;
            }
        },
        location: function () {
            return p_location;
        },
        ownLower: function () {
            return flagOwnLower;
        },
        slot: function () {
            return $("#ddlSlot").val();
        },
        installment: function () {
            return $("#ddlInstallment").val();
        }
    },
    loadError: function (xhr, status, error) {
        $('#ErrorMessage').html(xhr.responseText);
        $('#ui-widget').show();
        $("#ErrorMessage").stop().show('slow');
    },
    //loadonce: true,
    pager: '#configPager',
    sortname: 'invdate',
    viewrecords: true,
    sortorder: "desc",
    //jsonReader: { repeatitems: false },
    caption: "caption",
    height: '100%',
    editurl: '/Controller/UpdateAction/' + Math.random(),
    multiselect: true,
    loadComplete: function () {
        $('#ErrorMessage').html("");
        $('#ui-widget').hide();
        $("#ErrorMessage").stop().hide('slow');

        gridLoaded = true;
    },
    onSelectRow: function (rowId) {

        //tried this but it is not working
        //jQuery("#frmac").editRow(rowId, true, null, null, '/Action/Controller/' + Math.random(), { slot: $("#ddlSlot").val(), installment: $("#ddlInstallment").val() });
    }
});

1 个答案:

答案 0 :(得分:0)

change log提到v3.8.2中引入了预定义格式化程序“动作”。即使我使用的是v3.8.1,它允许我使用'actions'格式化程序,其中很少的属性如keys,editbutton和deletebutton(我没有尝试其他的)但是,不支持extraparam,onEdit,onSearch。我已升级到v3.8.2并且我的问题已解决。