jqGrid从子网格中删除列标题

时间:2013-01-04 10:52:32

标签: javascript jquery jqgrid

我正在使用jqGrid-4.4.1子网格功能。

在我的情况下,我想从每行的 subGrid 中删除列标题。

我试过

var grid = $("#list");
var gview = grid.parents("div.ui-jqgrid-view"); 
gview.children("div.ui-jqgrid-hdiv").hide();

来自link。但是,它删除主表的标题,而不是子网格。

我发现了一种替代方案,但它基于HTML。 How to remove the table column headers from Jqgrid subgrid

此外,如何在展开行时从第一列中删除carot签名。

这是快照。我想删除标记为红色的边框。

enter image description here

1 个答案:

答案 0 :(得分:6)

通常,您使用正确的方法来隐藏列标题。唯一的问题是你需要使用正确的网格隐藏。通常,在subGridRowExpanded回调中创建子网格作为网格。 jqGrid创建<div>,你应该放置新的子网格。您获得的div的id作为subGridRowExpanded回调的第一个参数(有关详细信息,请参阅the documentation)。因此,创建一个带有一些id的子网格,通常基于div的id构造。如果您使用子网格的ID 而不是#list,您将能够隐藏子网格的列标题。

The demo证明了这样的实施:

enter image description here

以下是我用于the demo

的代码
var myData = [
        {
            id: "10",
            c1: "My Value 1",
            c2: "My Value 1.1",
            subgridData: [
                { id: "10", c1: "aa", c2: "ab" },
                { id: "20", c1: "ba", c2: "bb" },
                { id: "30", c1: "ca", c2: "cb" }
            ]
        },
        {
            id: "20",
            c1: "My Value 2",
            c2: "My Value 2.1",
            subgridData: [
                { id: "10", c1: "da", c2: "db" },
                { id: "20", c1: "ea", c2: "eb" },
                { id: "30", c1: "fa", c2: "fb" }
            ]
        },
        {
            id: "30",
            c1: "My Value 3",
            c2: "My Value 3.1",
            subgridData: [
                { id: "10", c1: "ga", c2: "gb" },
                { id: "20", c1: "ha", c2: "hb" },
                { id: "30", c1: "ia", c2: "ib" }
            ]
        }
    ],
    $grid = $("#list"),
    mainGridPrefix = "s_";

$grid.jqGrid({
    datatype: "local",
    data: myData,
    colNames: ["Column 1", "Column 2"],
    colModel: [
        { name: "c1", width: 180 },
        { name: "c2", width: 180 }
    ],
    rowNum: 10,
    rowList: [5, 10, 20],
    pager: "#pager",
    gridview: true,
    ignoreCase: true,
    rownumbers: true,
    sortname: "c1",
    viewrecords: true,
    autoencode: true,
    height: "100%",
    idPrefix: mainGridPrefix,
    subGrid: true,
    subGridRowExpanded: function (subgridDivId, rowId) {
        var $subgrid = $("<table id='" + subgridDivId + "_t'></table>"),
            pureRowId = $.jgrid.stripPref(mainGridPrefix, rowId);

        $subgrid.appendTo("#" + $.jgrid.jqID(subgridDivId));
        $subgrid.jqGrid({
            datatype: "local",
            data: $(this).jqGrid("getLocalRow", pureRowId).subgridData,
            colModel: [
                { name: "c1", width: 178 },
                { name: "c2", width: 178 }
            ],
            height: "100%",
            rowNum: 10000,
            autoencode: true,
            gridview: true,
            idPrefix: rowId + "_"
        });
        $subgrid.closest("div.ui-jqgrid-view")
            .children("div.ui-jqgrid-hdiv")
            .hide();
    }
});
$grid.jqGrid("navGrid", "#pager", {add: false, edit: false, del: false});

更新The answer显示了在调整主网格列的大小后如何实现子网格列的大小调整。