I find your question interesting. I invested some time and created the following demo which demonstrates how your requirements could be implemented. It displays
where one can use both horizontal scrollbars on the top or on the bottom of the grid. I used the answer as the basis of creating the top scroll bar. Additionally I included the part of code which fixed the size and position of all jqGrid dives in case if the user uses zoom in the web browser.
The most important part of the code of my answer I included below:
var $grid = $("#list");
// create the grid with some frozen columns
$grid.jqGrid({
....
});
var $gview = $grid.closest(".ui-jqgrid-view"),
$topToolbar = $gview.find(">.ui-userdata"),
$bdiv = $grid.closest(".ui-jqgrid-bdiv"),
resetTopToolbarHeight = function () {
var scrollbarHeight = 18; // some test value
$topToolbar.find(">div").height(scrollbarHeight);
$topToolbar.css("border-top", "0").css("height", "auto");
scrollbarHeight = $topToolbar.height() - scrollbarHeight;
$topToolbar.find(">div").height(scrollbarHeight);
$topToolbar.height(scrollbarHeight);
fixPositionsOfFrozenDivs.call($grid[0]);
};
// insert empty div in the top toolbar and make its width
// the same as the width of the grid
$topToolbar.css({ overflowX: "scroll", overflowY: "hidden"})
.append($("<div>").width($grid.width()));
// set the height of the div and the height of toolbar
// based on the height of the horizontal scrollbar
resetTopToolbarHeight();
// detect scrolling of topbar
$topToolbar.scroll(function () {
// synchronize the srollbar of the grid
$bdiv.scrollLeft($(this).scrollLeft());
});
// detect scrolling of the grid
$bdiv.scroll(function () {
// synchronize the srollbar of the toppbar
$topToolbar.scrollLeft($(this).scrollLeft());
});
// detect zoop of the page and adjust the
$(window).on("resize", function () {
resetTopToolbarHeight();
fixPositionsOfFrozenDivs.call($grid[0]);
});
Other parts of the code I get from my old answers about the usage of frozen columns.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…