如果我的网格数据滚动到当前窗口,是否可以在滚动数据时冻结列标题,以便列标题始终可见(如excel中)。我正在使用高度:'auto',因为我不想修复网格高度。提前谢谢......
答案 0 :(得分:2)
如果网格是页面上最顶层的元素,那么使用position: fixed
会很有帮助。代码可以是以下
var $hdiv = $($grid[0].grid.hDiv),
hOffset = $hdiv.offset(),
$cdiv = $($grid[0].grid.cDiv),
cOffset = $cdiv.offset(),
$bdiv = $($grid[0].grid.bDiv);
// change gbox position
$bdiv.parent().parent().css({
position: "relative",
top: $bdiv.offset().top,
left: 0});
// make header and capture fixed
$hdiv.css({
position: "fixed",
zIndex: 1,
top: hOffset.top - cOffset.top,
left: hOffset.left
});
$cdiv.css({
position: "fixed",
zIndex: 1,
top: 0,
left: cOffset.left,
width: $cdiv.width()
});
请参阅the demo。
答案 1 :(得分:1)
这是内置于jqgrid。但是,为了使用此功能,您需要调整网格本身的大小以适应窗口,然后在窗口调整大小时调整大小。这将允许滚动在网格本身内发生,而不是在整个文档中发生。见下文:
$(window).resize(function () {
resizeGrid();
});
$(window).load(function() {
resizeGrid();
});
function resizeGrid() {
var heightPadding = 200; // or whatever you want it to be
var widthPadding = 40; // or whatever you want it to be
$('#grid').setGridHeight($(window).height() - heightPadding);
$('#grid').setGridWidth($(window).width() - widthPadding);
}
答案 2 :(得分:0)
这似乎应该根据他们的文档和演示自动发生。尝试将高度设置为像素值,看看会发生什么。
答案 3 :(得分:0)
这项工作对我来说(没有网格css编辑)
document.getElementById("gview_" + gridID).style.height = "100%";
document.getElementById(gridID).parentNode.parentNode.style.height = "100%";
document.getElementById(gridID).parentNode.style.height = "100%";
document.getElementById(gridID).parentNode.style.overflow = "auto";
您必须在网格初始化后使用此代码,并且必须使用此ID调用网格来设置样式:
document.getElementById("gbox_" + gridID).style.width = "100%";
document.getElementById("gbox_" + gridID).style.height = "100%";
或
document.getElementById("gbox_" + gridID).style.top = "0px";
document.getElementById("gbox_" + gridID).style.left = "0px";
document.getElementById("gbox_" + gridID).style.bottom = "40px";
document.getElementById("gbox_" + gridID).style.right = "0px";
document.getElementById("gbox_" + gridID).style.position = "absolute";
和列标题始终可见!
希望这有帮助!