As a follow-up:
这篇文章中之前的代码最终被放弃了,因为它不可靠.根据jqGrid文档的建议,我现在使用以下API函数调整网格的大小:
jQuery("#targetGrid").setGridWidth(width);
要进行实际的调整大小,将实现以下逻辑的函数绑定到窗口的调整大小事件:
使用其父网格的clientWidth和(如果不可用)其offsetWidth属性计算网格的宽度.
执行完整性判断,确保宽度变化超过x像素(以解决某些特定于应用程序的问题)
最后,使用setGridWidth()更改网格的宽度
下面是处理大小调整的示例代码:
jQuery(window).bind('resize', function() {
// Get width of parent container
var width = jQuery(targetContainer).attr('clientWidth');
if (width == null || width < 1){
// For IE, revert to offsetWidth if necessary
width = jQuery(targetContainer).attr('offsetWidth');
}
width = width - 2; // Fudge factor to prevent horizontal scrollbars
if (width > 0 &&
// Only resize if new width exceeds a minimal threshold
// Fixes IE issue with in-place resizing when mousing-over frame bars
Math.abs(width - jQuery(targetGrid).width()) > 5)
{
jQuery(targetGrid).setGridWidth(width);
}
}).trigger('resize');
和示例标记:
<div id="grid_container">
<table id="grid"></table>
<div id="grid_pgr"></div>
</div>