调整浏览器大小时是否调整jqGrid的大小?

调整浏览器窗口大小时,有什么方法可以调整jqGrid的大小?我已经尝试过这里描述的方法,但是该技术在IE7中不起作用。



互换的青春
浏览 662回答 3
3回答

蝴蝶不菲

现在已经在生产环境中使用了一段时间,没有任何抱怨(可能需要一些调整才能在您的网站上看起来正确。例如,减去边栏的宽度,等等)$(window).bind('resize', function() {    $("#jqgrid").setGridWidth($(window).width());}).trigger('resize');

梦里花落0921

作为后续措施:由于不可靠,本文中显示的先前代码最终被放弃了。我现在按照jqGrid文档的建议,使用以下API函数调整网格大小:jQuery("#targetGrid").setGridWidth(width);为了进行实际的大小调整,将实现以下逻辑的函数绑定到窗口的resize事件:使用其父级的clientWidth和其offsetWidth属性(如果不可用)计算网格的宽度。执行健全性检查,以确保宽度变化超过x个像素(以解决某些特定于应用程序的问题)最后,使用setGridWidth()更改网格的宽度这是处理大小调整的示例代码:jQuery(window).bind('resize', function() {&nbsp; &nbsp; // Get width of parent container&nbsp; &nbsp; var width = jQuery(targetContainer).attr('clientWidth');&nbsp; &nbsp; if (width == null || width < 1){&nbsp; &nbsp; &nbsp; &nbsp; // For IE, revert to offsetWidth if necessary&nbsp; &nbsp; &nbsp; &nbsp; width = jQuery(targetContainer).attr('offsetWidth');&nbsp; &nbsp; }&nbsp; &nbsp; width = width - 2; // Fudge factor to prevent horizontal scrollbars&nbsp; &nbsp; if (width > 0 &&&nbsp; &nbsp; &nbsp; &nbsp; // Only resize if new width exceeds a minimal threshold&nbsp; &nbsp; &nbsp; &nbsp; // Fixes IE issue with in-place resizing when mousing-over frame bars&nbsp; &nbsp; &nbsp; &nbsp; Math.abs(width - jQuery(targetGrid).width()) > 5)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; jQuery(targetGrid).setGridWidth(width);&nbsp; &nbsp; }}).trigger('resize');和示例标记:<div id="grid_container">&nbsp; &nbsp; <table id="grid"></table>&nbsp; &nbsp; <div id="grid_pgr"></div></div>
打开App,查看更多内容
随时随地看视频慕课网APP