How can I get my (first) jqGrid to fill its parent container without losing its horizontal scrollbar by putting it too far down? (The scrollbar being the one created by the scroll: 1
option, e.g., "virtual scrolling".) It seems to use the height I give it without allowing for the scrollbar, and so the scrollbar ends up past the bottom of the area I'm trying to keep it in. I've seen these two questions about resizing the grid (and their answers), but while useful (they got me this far), they don't address the scrollbar problem.
The page's layout looks like this (it's not mine; I might be able to get it changed, but it would best if I could avoid that — with the exception that I can do just about anything I want with gridWrapper
):
HTML:
<body>
<div id="pageHeader">Header section</div>
<div id="pageBody">
<div id="gridWrapper" style="height: 100%">
</div>
</div>
<div id="pageFooter">Footer section</div>
</body>
CSS:
body {
margin: 0;
padding: 0;
font-family: verdana, sans-serif;
}
#pageHeader {
width: 100%;
height: 99px;
border-bottom: solid 1px #ccc;
}
#pageBody {
background-color: #fff;
position: fixed;
top: 100px;
bottom: 45px;
left: 0;
right: 0;
}
#pageFooter {
background-color: #eee;
position: fixed;
left: 0;
right: 0;
bottom: 0;
height: 44px;
border-top: solid 1px #ccc;
}
My grid creation/sizing code looks like this (you can tell it's testing/prototyping code):
function createGrid(data) {
var colNames, colModel, index, grid, gridParent, theFudge, heightFudge = 0;
colNames = [
"One", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Eleven", "Twelve", "Thirteen", "teen", "Fifteen",
"Sixteen", "Seventeen", "Eightteen", "Nineteen", "Twenty",
"Twenty One", "Twenty Two", "Twenty Three", "Twenty Four",
"Twenty Five"
];
colModel = [];
for (index = 0; index < colNames.length; ++index) {
colModel.push({
name: "col" + index,
id: "col" + index,
width: 75
});
}
gridParent = $("#gridWrapper");
grid = $('<table id="theTable"></table>').appendTo(gridParent);
grid.jqGrid({
datatype: 'local',
data: data,
height: gridParent.height() - heightFudge,
width: gridParent.width(),
shrinkToFit: false,
colNames: colNames,
colModel: colModel,
rownumbers: true,
rownumWidth: 75,
scroll: 1
});
$(window).resize(resizeGrid);
function resizeGrid() {
grid.jqGrid('setGridWidth', gridParent.width());
grid.jqGrid('setGridHeight', gridParent.height() - heightFudge);
grid.trigger('reloadGrid');
}
}
You see that heightFudge
value (which in the above is just 0
). If I don't fudge the height, the scrollbar is beyond the bottom of pageBody
, intruding on (and being hidden by) pageFooter
. On my browser with my fonts and my window decorations etc., etc., etc., the fudge factor (height of the scrollbar) is 24 pixels. But of course that will vary.
How can I get the grid to fill the grid wrapper and keep its horizontal scrollbar within the height I give it? (Or how can I reliably determine the fudge factor at runtime, but that seems kludgy to me.)
Here's a live copy of the above (source link), with data for the table and controls for experimenting with the fudge and such.