【问题标题】:jqGrid remove column headers from subgridjqGrid 从子网格中删除列标题
【发布时间】:2012-12-18 19:24:16
【问题描述】:

我正在使用jqGrid-4.4.1 subGrid 功能。

在我的例子中,我想为每一行从 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

另外,如何在行展开时从第一列中删除胡萝卜符号。

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

【问题讨论】:

    标签: javascript jquery jqgrid


    【解决方案1】:

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

    The demo 演示了这样的实现:

    下面是我用于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 展示了如何在调整主网格的列大小后实现子网格列的大小调整。

    【讨论】:

    • 非常感谢您的回复。但这也删除了主标题。我想保留主网格的标题。
    • @HardikMishra:抱歉,输入错误。应该使用$subgrid.closest 而不是$subgrid.parents。我修改了答案和演示。
    • 嗨 Oleg.. 如果可能的话,您能否提供关于 stackoverflow.com/questions/14216113/… 的任何指针
    猜你喜欢
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多