jqGrid额外的POST数据editURL与内联编辑

时间:2015-12-29 23:44:33

标签: jquery jqgrid

需要帮助将addtional editURL数据发送到服务器。下面是我的代码,但它无法正常工作

progGrid.jqGrid({
    url         : rootURLProgExecList,
    editurl     : '/ProgGrid.php',
    editData    : {'action':'weekID','userID':userID},
    mtype       : "POST",
    postData    : {'action':'weekID','userID':userID},
    datatype    : "JSON",
    page        : 1,
    regional    : lang,
    colNames    : progWeekColName[lang],
    colModel    : [
                    { name: 'userID', width: 25, hidden: true },
                    { name: 'weekID', key: true, editable: true, width: 20, editrules : { required: true, integer:true, minValue:1} },
                  ],
    loadonce    : true,
    autowidth   : true,
    height      : 445,
    rowNum      : 20,
    caption     : progGridCaption,
    subGrid     : true, // set the subGrid property to true to show expand buttons for each row
    subGridRowExpanded  : showChildGrid, // javascript function that will take care of showing the child grid
    subGridOptions      : {
            expandOnLoad: false, // expand all rows on load
            plusicon    : "fa fa-plus-circle",
            minusicon   : "fa fa-minus-circle"
    },
    subGridBeforeExpand: function(divid, rowid) {
    var expanded = jQuery("td.sgexpanded", "#progGrid")[0];
        if(expanded) {
            setTimeout(function(){
                $(expanded).trigger("click");
            }, 100);
        }
    },
    shrinkToFit : true,
    sortorder   : "asc",
    hidegrid    : false,
    gridview    : true,
    pgbuttons   : false,     // disable page control like next, back button
    pgtext      : null,
    viewrecords : true,
    recordtext  : '{0}-{1} / {2}',
    pager       : progGridPager
})
.navGrid(progGridPager, {edit: false, add: false, del: false, refresh: true, view: false, search:false})
.inlineNav(progGridPager,{edit: true, add: true, del: true, cancel: true, refresh : true,
            editParams: {keys: true},
            addParams : {keys: true}});

    // the event handler on expanding parent row receives two parameters
    // the ID of the grid tow  and the primary key of the row  subgrid_id
function showChildGrid(parentRowID, parentRowKey) {
    var childGridID = parentRowID + "_day";
    var childGridPagerID = parentRowKey + "_pager";
    // send the parent row primary key to the server so that we know which grid to show
    // add a table and pager HTML elements to the parent grid row - we will render the child grid here
    $('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');

    $("#" + childGridID).jqGrid({
        url         : rootURLProgExecList,
        editurl     : '/ProgGrid.php',
        editData    : {'action':'day', 'userID':userID,'weekID' : parentRowKey},
        mtype       : "POST",
        postData    : {'action':'day','userID':userID,'weekID' : parentRowKey},
        datatype    : "json",
        page        : 1,
        regional    : lang,
        caption     : progWeekCaption[lang],
        colNames    : progDayColName[lang],
        colModel    : [
                        { name: 'week_ID',  width: 75, hidden: true },
                        { name: 'dayID', key: true, width: 100, editable:true, editrules : { required: true, integer:true, minValue:1, maxValue:7}, },
                      ],
        loadonce    : true,
        autowidth   : true,
        //width     : 500,
        height      : '100%',
        subGrid     : true, // set the subGrid property to true to show expand buttons for each row
        subGridRowExpanded: showThirdLevelChildGrid, // javascript function that will take care of showing the child grid
        subGridOptions      : {
                expandOnLoad: false, // expand all rows on load
                plusicon: "fa fa-plus-circle",
                minusicon: "fa fa-minus-circle"
        },
        subGridBeforeExpand: function(divid, rowid) {
        // #grid is the id of the grid
        var expanded = jQuery("td.sgexpanded", "#" + childGridID )[0];
            if(expanded) {
                setTimeout(function(){
                    $(expanded).trigger("click");
                }, 100);
            }
        },
        shrinkToFit : true,
        sortorder   : "asc",
        hidegrid    : true,
        gridview    : true,
        pgbuttons   : false,     // disable page control like next, back button
        pgtext      : null,
        viewrecords : true,
        recordtext  : '{0}-{1}/{2}',
        pager: '#' + childGridPagerID
    })
    .navGrid('#' + childGridPagerID, {edit: false, add: false, del: false, refresh: true, view: false, search:false})
    .inlineNav('#' + childGridPagerID,{edit: true, add: true, del: true, cancel: true, refresh : true, editParams: {keys: true,}, addParams: {keys: true}});
}

我尝试将其他数据添加到addParams和editParams中 addParams:{keys:true,{&#39; action&#39;:&#39; weekID&#39;,&#39; userID&#39;:userID}} editParams:{keys:true,{&#39; action&#39;:&#39; weekID&#39;,&#39; userID&#39;:userID}}没有运气。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:2)

首先,addParams选项应该是

addParams: {addRowParams: {keys: true}}

而不是

addParams : {keys: true}

要在内联编辑期间添加更多自定义数据,例如{'action':'weekID','userID':userID},您可以使用extraparam

.navGrid(progGridPager, {edit: false, add: false, del: false, search: false})
.inlineNav(progGridPager, {
    editParams: {keys: true, extraparam: {action:'weekID', userID:userID}},
    addParams: {addRowParams:{keys:true,extraparam:{action:'weekID',userID:userID}}}});

我看到你使用Guriddo jqGrid JS。我开发了jqGrid的替代fork:free jqGrid(当前版本是4.12.0)。它支持简化形式的提供选项,如the wiki article中所述。如果您使用这些选项,您可以减少代码并简化它。

我会严格建议您至少对子网格使用idPrefix选项。例如,您可以使用idPrefix: "s_" + parentRowKey + "_"。防止id重复是非常重要的。

相关问题