问题描述
我不需要为所有样式设置自定义样式,而是为nattable中的某些列设置样式.我不能这样设置配置:
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!
推荐答案
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配置文档
To apply the CELL_LABEL label to your column follow the instructions from NatTable configuration docs
按照总体设计惯例,图层可以在其中添加标签 细胞.为了将标签粘贴到单元,您需要实施 IConfigLabelAccumulator接口.这 每次调用IConfigLabelAccumulator.accumulateConfigLabels() 层.每层都可以将其标签添加到LabelStack.
Following the overall design convention, Layers can add labels to cells. In order to attach a label to a cell(s) you need to implement the IConfigLabelAccumulator interface. The IConfigLabelAccumulator.accumulateConfigLabels() is called on each layer. Every layer can add its labels to the LabelStack.
开箱即用的是最常见的用例,包括但 不限于:
The most common use cases are available out of the box, including but not limited to:
CellOverrideLabelAccumulator-将标签应用于包含 指定的数据值ColumnOverrideLabelAccumulator-应用标签 到列中的所有单元格您可以为您的自定义实现 自己的规则
CellOverrideLabelAccumulator - applies labels to cell(s) containing a specified data value ColumnOverrideLabelAccumulator - applies labels to all cells in a column You can make custom implementations for your own rules
这篇关于如何为nattable中的某些列设置自定义样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!