调整浏览器大小时调整jqGrid大小? [英] Resize jqGrid when browser is resized?

查看:102
本文介绍了调整浏览器大小时调整jqGrid大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览器窗口调整大小时,有没有办法调整 jqGrid 的大小?我已经尝试了描述的方法 here ,但该技术在IE7中无法使用。

up:

这篇文章中显示的以前的代码最终被放弃了,因为它不可靠。按照jqGrid文档的建议,我现在使用以下API函数调整网格大小:
$ b

  jQuery(#targetGrid ).setGridWidth(宽度); 

要进行实际的大小调整,实现以下逻辑的函数将绑定到窗口的resize事件:




  • 使用其父级的clientWidth和(如果不可用)其offsetWidth属性计算网格的宽度。执行完整性检查以确保宽度变化超过x像素(解决一些特定于应用程序的问题)


  • 最后,使用setGridWidth()来改变网格的宽度
    示例代码来处理调整大小:

    $ p $ jQuery(window).bind('resize',function(){

    //获取父容器的宽度
    var width = jQuery(targetContainer).attr('clientWidth');
    if(width == null || width< 1){
    //对于IE,必要时还原为offsetWidth
    width = jQuery(targetContainer).attr('offsetWidth');
    }
    width = width - 2; // Fudge factor to prevent水平滚动条
    if(宽度> 0&&
    //只有在新宽度超过最小阈值时才调整大小
    //修复鼠标悬停时就地调整大小的IE问题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>


    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.

    解决方案

    As a follow-up:

    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:

    • Calculate the width of the grid using its parent's clientWidth and (if that is not available) its offsetWidth attribute.

    • Perform a sanity check to make sure width has changed more than x pixels (to work around some application-specific problems)

    • 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');
    

    And example markup:

    <div id="grid_container">
        <table id="grid"></table>
        <div id="grid_pgr"></div>
    </div>
    

    这篇关于调整浏览器大小时调整jqGrid大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆