【问题标题】:postData not working in JqGridpostData 在 JqGrid 中不起作用
【发布时间】:2015-03-29 23:33:47
【问题描述】:

我正在尝试向 JqGrid 表添加新行,请求中发送的 json 被服务器接收。现在我正在尝试使用

向json添加新参数
postData : {my_parameter: "my_id"}

但仍然没有发送my_parameter

我也尝试过保留 mtype : "GET" ,但它仍然没有在 json 中发送我的自定义参数。 请你帮帮我。

提前致谢。

   jQuery(grid_selector).jqGrid({
    data: griddata,
    datatype: "local",
    height: "auto",
    colNames:[' ', 'ID','Activity Name', 'Phase'],
    colModel:[
        {name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,
            formatter:'actions',
            formatoptions:{
                keys:true,
                //delbutton: false,//disable delete button

                delOptions:{recreateForm: true, beforeShowForm:beforeDeleteCallback},
                //editformbutton:true, editOptions:{recreateForm: true, beforeShowForm:beforeEditCallback}
            }
        },
        {name:'id',index:'id', width:60, sorttype:"int", editable: true},
        {name:'name',index:'name', width:150,editable: true,edittype:"select",editoptions:{value:activity_val}},
        {name:'phase',index:'phase', width:90, editable: true,edittype:"select",editoptions:{value:"Phase1:Phase I;Phase2:Phase II;Other:Other"}},
    ],

    viewrecords : true,
    rowNum:20,
    rowList:[10,20,30],
    pager : pager_selector,
    altRows: true,
    gridview: true,
    //toppager: true,

    multiselect: false,
    //multikey: "ctrlKey",
    multiboxonly: true,

    loadComplete : function() {
        var table = this;
        setTimeout(function(){
            styleCheckbox(table);

            updateActionIcons(table);
            updatePagerIcons(table);
            enableTooltips(table);
        }, 0);
    },
    editurl: '/del_row/',//nothing is saved
    cellEdit: true,
    postData: {MyId :function() { return $('#MyId').val();}},
    caption: "Activty Phase Mapping"
});

【问题讨论】:

    标签: jquery html json django jqgrid


    【解决方案1】:

    postData只有在使用非本地数据时才会在填充网格时使用url 已定义并且您使用datatype: "json"datatype: "json")。

    如果您需要在编辑网格期间发布其他参数,您应该使用与您使用的编辑模式相对应的选项或回调。您发布的代码使用单元格编辑 (cellEdit: true)。因此,您需要使用 cellurl 参数指定将数据发布到的 URL。您可以使用例如beforeSubmitCell 回调来扩展将发送到 URL 的数据:

    cellEdit: true,
    cellurl: '/someUrl',
    beforeSubmitCell: function () {
        return { MyId: return $('#MyId').val() };
    }
    

    在上面的代码中我另外替换了cellurl

    【讨论】:

      猜你喜欢
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2011-09-05
      相关资源
      最近更新 更多