【问题标题】:GWT grid cells don't wrapGWT 网格单元不换行
【发布时间】:2021-06-02 11:52:00
【问题描述】:

我正在使用 GWT GridPanel。我希望其中一列可以换行,但我尝试过的没有任何效果。在关联的 css 文件中,我尝试过:

.x-grid3-cell-inner .x-grid3-col-note {
    overflow: visible; white-space: normal !important;
}

其中 note 是我要包装的列的名称。没用。 我试过了:

.x-grid3-cell {
    white-space:wrap;
}

没用。我试过了:

.x-grid3-cell-inner {
    cell-wrap: true;
}

没用。任何人都有一个简单可行的解决方案?

编辑:我也尝试像这样在 ColumnConfig 中设置 id:

ColumnConfig[] columns = new ColumnConfig[] {
        new ColumnConfig("Note", "note", 130, true, null, "note"),
        new ColumnConfig("Date", "date", 65, true)
};

ColumnConfig c = columns[0];
c.setId("noteColumn");

然后在我添加的css中:

#noteColumn {
    overflow: visible; white-space: normal !important;
}

但这也没有用。

【问题讨论】:

  • 这看起来不像 GWT 的内置网格样式 - 你能提供更多上下文吗?
  • 创建 GWT 项目时,它会创建一个 css 模板文件 ProjectName.css。当我查看呈现的 html 时,我看到了目标表格单元格的上述类名。所以我在该文件中添加了 css 以尝试让它们换行。

标签: javascript java css gwt


【解决方案1】:

这是GWT-Ext widget。在文档中有一些关于如何包装单元格内容的示例。

例如,使用它来全局包装所有单元格内容

 .x-grid3-cell-inner {
      overflow: visible; white-space: normal !important;
 }

你可以在ColumnConfig中使用setId()方法:

将 id 分配给 ColumnConfig 会导致列 dom 元素具有该 ID。这对于将自定义 css 应用于整个列很有用。

如果id = note 那么css规则应该是:

.x-grid3-col-note {
      overflow: auto; white-space: normal !important;
 }

【讨论】:

  • 再次感谢亚当!你的第一个建议奏效了。第二个没有,除非我做错了。我将在帖子中添加我的尝试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-07
  • 1970-01-01
  • 1970-01-01
  • 2014-11-28
  • 1970-01-01
相关资源
最近更新 更多