jqgrid: subgrid toolbar does not display

后端 未结 1 1170
花落未央
花落未央 2020-12-11 13:30

I\'m using jqgrid 4.8.2. I\'m trying to follow along with the examples on the demo site. I\'ve created a parent grid and need to show a subgrid (as a grid). For some reaso

相关标签:
1条回答
  • 2020-12-11 14:00

    You mean probably that the pager (not the toolbar) will be not displayed in subgrids.

    The reason is very easy if you understand how the grid as subgrid feature works in jqGrid. If you just add subGrid: true to the grid (to the main grid) then jqGrid insert additional column in colModel with the name "subgrid". The column will have + icons which can be used to "expand" subgrid. If the user clicks on the + icon then the new row will be added under the row with + icon. The row will contains <td> with the icon and <td> with span over the whole grid. The last <td> will contains the subdrid. Before call of subGridRowExpanded jqGrid creates empty <div> in the cell with id constructed from grid id, "_" and rowid (of expanding row). The first parameter of subGridRowExpanded callback (subgrid_id in your code) contains the id of the empty <div>. The picture below shows the described above

    I marked in red color the subgrid row. The id of empty div is jqGrid_10 in the above example because the rowid is 10 and the grid id is jqGrid.

    It's important to understand that you have to create <table> element for subgrid dynamically inside of subGridRowExpanded callback. If you want that the subgrid have the pager then you have to create <div> for the pager too. The problem in your code: you just use pager: "#jqGridPager" + "_" + subgrid_id option for subgrid, but you don't created <div> with the corresponding id.

    The next problem: every row (<tr>) of subgrid will have id attribute (rowid). So one have to assign it. The user can open multiple subgrids at the same time. The problem is that it's possible to have id duplicates because of usage the same id in two different subgrids or between subgrid and the main grid. To fix the problem with id conflicts it's strictly recommended to use idPrefix parameter for subgrid with the value which is different for every subgrid.

    A possible fixed implementation of subGridRowExpanded could be the following:

    subGridRowExpanded: function (subgridDivId, rowid) {
        var $subgrid = $("<table id='" + subgridDivId + "_t'></table>"),
            subgridPagerId = subgridDivId + "_p";
        $("#" + subgridDivId)
            .append($subgrid)
            .append("<div id='" +subgridPagerId + "'></div>");
    
        $subgrid.jqGrid({
            url: 'servlet/getProductWarehouses',
            postData: {
                q: 2,
                id: rowid,
                productId: rowid
            },
            datatype: "local",
            colModel: [
                { label: 'Product ID', name: 'ProductId', width: 75, hidden: true },
                { label: 'Whse ID', name: 'WhseId', width: 90, key: true },
                { label: 'Whse Name', name: 'WhseName', width: 90 },
                { label: 'Qty', name: 'Quantity', width: 80 },
                { label: 'Included?', name: 'Included', width: 80,
                    editable: true,
                    edittype: "checkbox",
                    editOptions: {value:"Yes:No"} }
            ],
            viewrecords: true,
            height: '100%',
            width: 400,
            rowNum: 5,
            //idPrefix: subgridDivId + "_",
            idPrefix: rowid + "_",
            pager: "#" + subgridPagerId
        });
    }
    

    By the way you use key: true property for the column ProductId of the main grid. So the rowid of the main grid will be the same as the ProductId. Because of that I used productId: rowid in the above code. One more remark. I used idPrefix: rowid + "_" for subgrid. One can use successfully other values in the same way, for example idPrefix: subgridDivId + "_".

    0 讨论(0)
提交回复
热议问题