问题
I have the same problem as detailed in the post Resize jqGrid based on number of rows?
Some of the suggestions (which seem totally logical) do not work because when I try to get the height of the grid using var height = $("#TableId").height();
it returns what was set when setting up the grid, i.e. "100%"...
How do I get the height in pixels?
回答1:
It was something wrong in your previous experiments. How you can see from the demo the jQuery.height method get you the height of the grid in pixel if you use height:'100%'
or height:'auto'
in the jqGrid definition.
By the way if you want to know the full grid height including the capture, headers, pager and so on you should get hight of $("#gbox_TableId").height()
instead of $("#TableId").height()
.
回答2:
Jqgrid creates a lot of extra markup wrapping your initial table. So, to change its height, you can do this:
$("#TableId").closest(".ui-jqgrid-bdiv").height(200);
Hope this helps. Cheers
回答3:
Simple use
$('.ui-jqgrid-bdiv').css('height', '100%');
来源:https://stackoverflow.com/questions/5870057/resize-jqgrid-based-on-number-of-rows-grid-height