Resize jqGrid when browser is resized?(调整浏览器大小时调整jqGrid的大小?)
问题描述
当浏览器窗口调整大小时,有没有办法调整 jqGrid 的大小?我已经尝试过描述的方法 here 但该技术在 IE7 中不起作用.
Is there any way to resize a jqGrid when the browser window is resized? I have tried the method described here but that technique does not work in IE7.
推荐答案
作为后续:
本文中显示的先前代码最终被放弃,因为它不可靠.按照 jqGrid 文档的建议,我现在使用以下 API 函数来调整网格的大小:
The previous code shown in this post was eventually abandoned because it was unreliable. I am now using the following API function to resize the grid, as recommended by the jqGrid documentation:
jQuery("#targetGrid").setGridWidth(width);
要进行实际的调整大小,将实现以下逻辑的函数绑定到窗口的调整大小事件:
To do the actual resizing, a function implementing the following logic is bound to the window's resize event:
使用其父级的 clientWidth 和(如果不可用)它的 offsetWidth 属性来计算网格的宽度.
Calculate the width of the grid using its parent's clientWidth and (if that is not available) its offsetWidth attribute.
执行完整性检查以确保宽度变化超过 x 像素(以解决一些特定于应用程序的问题)
Perform a sanity check to make sure width has changed more than x pixels (to work around some application-specific problems)
最后,使用 setGridWidth() 来改变网格的宽度
Finally, use setGridWidth() to change the grid's width
这是处理调整大小的示例代码:
Here is example code to handle resizing:
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>
这篇关于调整浏览器大小时调整jqGrid的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:调整浏览器大小时调整jqGrid的大小?


基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01