jqGrid-有没有办法始终显示垂直滚动条? [英] jqGrid - Is there a way to always display a vertical scrollbar?

查看:359
本文介绍了jqGrid-有没有办法始终显示垂直滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有几个jqGrid,这些jqGrid可能包含也可能不包含足够的行以需要垂直滚动条.但是,在创建行之后,可以将行动态添加到这些网格中,以便网格最终可能需要滚动条.

My application has several jqGrids that may or may not contain enough rows to require a vertical scrollbar. But rows may be dynamically added to these grids after they have been created, so that a grid may eventually require a scrollbar.

问题是,如果网格没有足够的行来需要滚动条,则网格的右侧将有空白空间.我想以某种方式解决此问题-始终显示垂直滚动条,或在必要时以某种方式动态添加它.

The problem is that if the grid does not have enough rows to require a scrollbar, there is empty space on the right-hand side of the grid. I would like to fix this somehow - either always display the vertical scrollbar, or somehow dynamically add it when necessary.

我尝试将以下CSS添加到网格的.ui-jqgrid-bdiv div中:

I tried adding the following CSS to the grid's .ui-jqgrid-bdiv div:

overflow-y: scroll;

使用以下jQuery(我知道代码很丑陋):

Using the following jQuery (the code is ugly, I know):

$("#mygrid").closest(".ui-jqgrid-bdiv").attr("style",
$("#mygrid").closest(".ui-jqgrid-bdiv").attr("style") + " overflow-y: scroll; ");

这在Firefox和Chrome上工作正常,但是在IE上,网格永远不会显示滚动条(无论我添加多少行,它们都会添加到网格底部,而垂直滚动条永远不会出现).

This works fine on Firefox and Chrome, but on IE the grid never displays the scrollbar (no matter how many rows I add, they are added to the bottom of the grid and a vertical scrollbar never appears).

感谢您的帮助!

推荐答案

overflow-y是CSS3,IE尚未完全支持它(叹息...)

overflow-y is CSS3, and it's not yet fully supported by IE (sigh...)

因此,我想您可以在不做任何其他标记的情况下对此做的仅有2件事,就是使用overflow: auto(由浏览器决定)或overflow: scroll,这将强制垂直和水平滚动条.

So, I guess the only 2 CSS things you can do about this, without any other markup involved, is to use either overflow: auto (which will let the browser decide) or overflow: scroll, which will force both the vertical AND the horizontal scrollbars.

一种解决方法是将整个网格以最小高度包装在更大的div中,因此将其设置为等于浏览器窗口+ 1px.这样,您将强制使用垂直滚动条.

A workaround may be to wrap the whole grid in a bigger div with a min-height, so you set that equal to the browsers window + 1px. That way you'll force a vertical scrollbar.

在所有浏览器中设置最小高度可能都比较棘手,但是我发现这在大多数浏览器中都很好用.

Setting a min-height may be tricky to do in all browsers, but I found this works great in most of them.

.the-wrapper{
  height: auto !important; /* for real browsers*/
  height: 601px;           /* IE6 will use this a min-height. Use any height you need - you can even set this using JavaScript depending on the browser window height */
  min-height: 601px;       /* for real browsers - same value as height */
}

当然,这会在网格下方添加一些空间.欢迎登机!

Of course, this will add some space below the grids. Welcome aboard!

这篇关于jqGrid-有没有办法始终显示垂直滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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