GWT 在 DataGrid 中隐藏分组数据

GWT Hide grouped data in DataGrid

我们正在使用 GWT。我有一个 DataGrid,在左侧的列中有许多重复值。我想隐藏这些。例如:

我有:

Town        | Address             | Color
------------------------------------------
Springfield | Springfield Heights | Blue
Springfield | Bum town            | Red
Springfield | Little Italy        | Blue
Shelbyville | Manhattan Square    | Green
Shelbyville | Chinatown           | Red

我想要:

Town        | Address             | Color
------------------------------------------
Springfield | Springfield Heights | Blue
            | Bum town            | Red
            | Little Italy        | Blue
Shelbyville | Manhattan Square    | Green
            | Chinatown           | Red

我尝试了一些方法,但它们不适用于可排序列。有没有标准的方法来做到这一点?

您可以覆盖 getCellStyleNames 用于城镇列的单元格。此方法为您提供上下文,您可以使用它来查看此单元格在列中的位置 (context.getIndex())。使用此信息,您可以将此单元格中的值与其上方单元格中的值(如果有)进行比较。如果相同,return 隐藏此单元格中值的样式。

请注意,如果您在为您的单元格覆盖 getValue 时简单地 return 空值,它将不起作用,因为它会使下一个单元格显示其值,即使它是相同的。当然,您可以通过查找直到找到 non-empty 单元格来解决此问题,但是覆盖 getCellStyleNames 并简单地隐藏重复值看起来是一个更简单的解决方案。

因为这是您的单元格中的一个方法,所以它在更新、对列进行排序等方面应该表现良好。