If your code is lengthy, it's not the aim of stackoverflow for someone else to debug it for you. It would be helpful if you could create a small demonstration that showcases the issue.
Upon debugging, I noticed that the grid initially lacks a horizontal scrollbar. Free jqGrid has a mechanism to determine whether the grid needs a horizontal scrollbar after the data has been loaded. It adjusts the padding-right
of hbox (a div nested within hdiv
with the class ui-jqgrid-hbox
) based on the width of the scroll bar:
bDiv.offsetWidth - bDiv.clientWidth
(refer to
this line and
this one in the code).
If you click on the Reload grid button after encountering the scrollbar issue, it should correct itself. Therefore, it seems likely that modifications made to the page post-data loading are triggering the appearance of horizontal scroll bars. Since jqGrid doesn't detect these changes, the problem persists.
To address this, manually invoke the fixScrollOffsetAndhBoxPadding
method after implementing any unclear modifications that lead to horizontal scroll bars (e.g., adjusting the grid's width with
$grid.jqGrid('setGridWidth', $('#grid1container').width(), false);
).
You can simply include the following call:
$grid[0].fixScrollOffsetAndhBoxPadding();
somewhere after the grid's scrollbar is generated. This method is public and part of the grid's DOM (refer to this line). The provided code snippet should resolve the issue.
Executing
$("#grid")[0].fixScrollOffsetAndhBoxPadding();
in the browser console confirms that the problem is resolved.