gpt4 book ai didi

javascript - jqGrid 从子网格中删除列标题

转载 作者:数据小太阳 更新时间:2023-10-29 05:19:31 27 4
gpt4 key购买 nike

我正在使用 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

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

这是截图。我想删除标记为红色的边框。

enter image description here

最佳答案

通常,您使用正确的方式来隐藏列标题。唯一的问题是您需要使用正确的网格隐藏。通常在 subGridRowExpanded 回调中创建子网格作为网格。 jqGrid 创建 <div> 你应该放置新子网格的地方。您获得的 div 的 id 作为 subGridRowExpanded 回调的第一个参数(有关更多详细信息,请参见 the documentation)。因此,人们创建了带有一些通常基于 div 的 id 构造的 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 展示了如何在调整主网格列的大小后实现子网格列的大小调整。

关于javascript - jqGrid 从子网格中删除列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14155735/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com