0

I need to set a custom style not for all, but some columns in a nattable. I can't set the configuration like this:

natTable.addConfiguration(new DefaultNatTableStyleConfiguration());

because this sets the configuration to the whole table. I have to override the configuration only to specific columns. In my case the columns should have the horizontal align set like this:

setHAlign(HorizontalAlignmentEnum.RIGHT);

How can I achieve this? Thanks!

4

1 回答 1

2

来自NatTable 样式文档

要启用条件样式,需要在 IConfigRegistry 中针对之前定义的标签注册自定义样式。

Style style = new Style();
// You can set other attributes here 
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_RED);

configRegistry.registerConfigAttribute(
    CellConfigAttributes.CELL_STYLE,    // attribute to apply
    style,                  // value of the attribute
    DisplayMode.NORMAL,         // apply during normal rendering
    CELL_LABEL);    

        // apply for all cells with this label

要将 CELL_LABEL 标签应用到您的列,请按照NatTable 配置文档中的说明进行操作

将标签附加到单元格

遵循整体设计约定,图层可以为单元格添加标签。为了将标签附加到单元格,您需要实现 IConfigLabelAccumulator 接口。IConfigLabelAccumulator.accumulateConfigLabels() 在每一层上调用。每个层都可以将其标签添加到 LabelStack。

最常见的用例是开箱即用的,包括但不限于:

CellOverrideLabelAccumulator - 将标签应用于包含指定数据值的单元格 ColumnOverrideLabelAccumulator - 将标签应用于列中的所有单元格 您可以为自己的规则进行自定义实现

于 2015-03-02T08:33:05.800 回答