我正在寻找修复jqgrid列标题和固定页脚。当jqgrid还有其他项目与数据时,我正在寻找修复标题,以便用户始终知道他在看什么。
Here is the sample for what I am looking for
注意,我在这里看浏览器滚动条。 jqgrid支持这个吗?
修改
因为JQGrid毕竟是html表,所以我尝试使用jQuery TH Float Plugin。 现在事实证明JqGrid由三个表组成 一个用于标题,一个用于数据,另一个用于页脚。所以我似乎要么修改thfloat以适应这个或者提出其他的东西......
答案 0 :(得分:1)
这是一个难以破解的难题。
我得到了它的工作 第一个css覆盖默认值,即overflow:hidden to
.ui-jqgrid .ui-jqgrid-sdiv{overflow:visible;}
.ui-jqgrid .ui-jqgrid-hdiv{overflow:visible;}
在javascript上JQuery来解救我实现了以下
function screenBottom() {
return $(window).scrollTop() + $(window).height();
}
$(window).scroll(function () {
var dataTableTop = dataTable.offset().top;
var dataTableHeight = dataTableTop + dataTable.outerHeight();
var windowTop = $(window).scrollTop();
var windowBottom = screenBottom();
//Scroll down
if (windowTop > dataTableTop - headerTable.height()
&& windowTop < (dataTableHeight - headerTable.height())) {
headerTable.offset({ top: windowTop, left: headerTable.offset().left });
}
//For footer
if (windowBottom > dataTable.offset().top + footerTable.outerHeight()
&& windowBottom < dataTableHeight + footerTable.outerHeight()) {
footerTable.offset({ top: windowBottom - footerTable.outerHeight(), left: footerTable.offset().left });
}
//Re adjust of the movement is too fast
if (windowTop < (dataTableTop - headerTable.height())
&& dataTableTop < (headerTable.offset().top + headerTable.height())) {
headerTable.offset({ top: dataTable.offset().top - headerTable.height(), left: headerTable.offset().left });
}
if (windowBottom > dataTableHeight + footerTable.outerHeight()) {
footerTable.offset({ top: dataTableHeight, left: footerTable.offset().left });
}
});
然后在调整窗口大小时检查页脚和页眉
$(window).resize(function () {
setInitializeHeadersAndFootersPosition();
});
function setInitializeHeadersAndFootersPosition() {
var dataTableTop = dataTable.offset().top;
var dataTableHeight = dataTableTop + dataTable.outerHeight();
var windowTop = $(window).scrollTop();
var windowBottom = screenBottom();
if (windowBottom > dataTableTop && windowBottom < dataTableHeight) {
footerTable.offset({ top: windowBottom - footerTable.outerHeight(), left: footerTable.offset().left });
}
if (footerTable.offset().top < dataTableHeight && windowBottom > dataTableHeight) {
footerTable.offset({ top: dataTableHeight, left: footerTable.offset().left });
}
if (windowTop > dataTableTop && windowTop < dataTableHeight) {
headerTable.offset({ top: windowTop, left: headerTable.offset().left }); //Header does not need the offset
}
}
答案 1 :(得分:0)
我以为我会提到如何填充缺失的变量。
//grid = $("#yourGrid").jqGrid( ...
dataTable = $(grid[0].grid.bDiv);
footerTable = $(grid[0].grid.sDiv);
headerTable = $(grid[0].grid.hDiv);
//my header column was behind the grid
headerTable.css('z-index', '1000');
setInitializeHeadersAndFootersPosition();
答案 2 :(得分:0)
$(window).bind('scroll', function () {
var _grid = $('#jqGrid'); // jqgrid name
var dataTable = $(_grid[0].grid.bDiv);
var headerTable = $(_grid[0].grid.hDiv);
var dataTableTop = dataTable.offset().top;
var dataTableHeight = dataTableTop + dataTable.outerHeight();
var windowTop = $(window).scrollTop();
var headerTablePosition = headerTable[0].style.position;
//Scroll down
if (windowTop > dataTableTop - headerTable.height() && windowTop < (dataTableHeight - headerTable.height()) && headerTablePosition != "fixed")
{
var leftOffset = headerTable.offset().left + 'px'; // grab the offset before changing postition
$(dataTable).css("top", (headerTable.height()+1) + "px"); // +1 to account for the border width of the header
headerTable[0].style.position = "fixed";
headerTable[0].style.top = "0px";
headerTable[0].style.left = leftOffset;
dataTable[0].style.height = "auto";
$($(_grid[0].grid.sDiv)).css("top", (headerTable.height() + 1) + "px"); // footer table, +1 to account for the border width of the header
var gridHeightString = $('#gview_jqGrid').css("height").replace("px", "");
var newGridHeight = parseInt(gridHeightString) + headerTable.height() + 1; // +1 to account for the border width of the header
$("#gview_jqGrid").css("height", newGridHeight + "px"); //outermost grid element
}
//Scroll up
else if (windowTop < (dataTableTop - headerTable.height()) && headerTablePosition == "fixed")
{
headerTable[0].style.left = "0px";
headerTable[0].style.position = "relative";
$(dataTable).css("top", "0px");
$($(_grid[0].grid.sDiv)).css("top", "0px"); // footer table
$("#gview_jqGrid").css("height", "100%"); //outermost grid element
}
});