Ext JS 中的自动换行网格单元
请随时回答!)
(这本身不是一个问题,我正在记录我使用 Ext JS 3.1.0 找到的解决方案。但是,如果您知道更好的解决方案, Ext JS Grid 对象没有允许自动换行文本的本机方法,但有一个 css
属性可以覆盖由 Ext JS Grid 对象创建的 TD
元素的内联 CSS网格。
不幸的是,TD
元素包含包装内容的 DIV
元素,并且 DIV
设置为 white-space:nowrap 由 Ext JS 的样式表定义,因此覆盖
TD
CSS 没有任何好处。
我将以下内容添加到我的主 CSS 文件中,这是一个简单的修复,似乎不会破坏任何网格功能,但允许我应用于 TD 的任何空白
设置通过直到DIV
。
.x-grid3-cell {
/* TD is defaulted to word-wrap. Turn it off so
it can be turned on for specific columns. */
white-space:nowrap;
}
.x-grid3-cell-inner {
/* Inherit DIV's white-space from TD parent, since
DIV's inline style is not accessible in the column
definition. */
white-space:inherit;
}
YMMV,但它对我有用,想将其作为解决方案发布,因为我无法通过搜索互联网找到可行的解决方案。
(This is not a question per se, I'm documenting a solution I found using Ext JS 3.1.0. But, feel free to answer if you know of a better solution!)
The Column config for an Ext JS Grid object does not have a native way to allow word-wrapped text, but there is a css
property to override the inline CSS of the TD
elements created by the grid.
Unfortunately, the TD
elements contain a DIV
element wrapping the content, and that DIV
is set to white-space:nowrap
by Ext JS's stylesheet, so overriding the TD
CSS does no good.
I added the following to my main CSS file, a simple fix that appears to not break any grid functionality, but allows any white-space
setting I apply to the TD to pass through to the DIV
.
.x-grid3-cell {
/* TD is defaulted to word-wrap. Turn it off so
it can be turned on for specific columns. */
white-space:nowrap;
}
.x-grid3-cell-inner {
/* Inherit DIV's white-space from TD parent, since
DIV's inline style is not accessible in the column
definition. */
white-space:inherit;
}
YMMV, but it works for me, wanted to get it out there as a solution since I couldn't find a working solution by searching the Interwebs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您只想将换行应用到一列,则可以添加自定义渲染器。
以下是要添加的函数:
然后将
renderer: columnWrap
添加到要换行的每个列If you only want to apply the wrapping to one column, you can add a custom renderer.
Here is the function to add:
Then add the
renderer: columnWrap
to each column you want to wrap不是“更好的解决方案”,而是类似的解决方案。我最近需要允许每个网格中的所有单元格都换行。我使用了类似的基于 CSS 的修复(这是针对 Ext JS 2.2.1):
我没有费心在 td 上设置样式,我只是直接选择单元类。
Not a "better solution", but a similar one. I recently needed to allow ALL cells in every grid to wrap. I used a similar CSS-based fix (this was for Ext JS 2.2.1):
I didn't bother with setting a style on the td, I just went right for the cell class.
如果您只想在某些列中换行文本并使用 ExtJS 4,则可以为列中的单元格指定 CSS 类:
并在 CSS 文件中:
If you only want to wrap text in certain columns and are using ExtJS 4, you can specify a CSS class for the cells in a column:
And in your CSS file:
其他解决方案是:
Other solution is that:
最好的方法是将 cellWrap 设置为 true,如下所示。
cellWrap: true
它在 EXTJS 5.0 中运行良好。
The best way to do is by setting the cellWrap to true as below.
cellWrap: true
Its working well in EXTJS 5.0.
如果您仍然想使用
css,请始终尝试在主题内使用 ui、变量等,或使用 style 属性设置样式。
use
If you still want to use css always try to work with ui's, variables, etc. within themes, or set the style with the style property.