Skip to main content

Configuration

Here you will find general information about configuring NatTable and the concepts involved.

ConfigRegistry

This is a global object holding the following kinds of configuration

  1. Styling
  2. Editing
  3. Comparators for sorting
  4. Any piece of arbitary information can be stored in this registry.

UiBindingRegistry

This is a global object holding the following kinds of configuration

  1. Key bindings
  2. Mouse bindings
You can find more information regarding bindings here.

DisplayMode

DisplayMode is a tag applied to a cell to identify the state the cell is in. Currently the following display modes are supported:

  1. Normal - The usual state
  2. Select - Signifies a cell is currently selected
  3. Edit - Signifies that the cell is being edited
For example, a cell might be colored white in normal mode but a gray color might be applied to it when it is in select mode.

Cell labels

Cell labels are a mechanism to tie configuration to specific cells. A cell label is a string/label which is attached to a cell.

For example,

  • We might attach a label 'error' to cells which meet certain criteria. While painting all cells with the label 'error' will be painted red.
  • We can attach a label 'checkbox' to all cell holding a boolean value. While painting all cells with the label 'checkbox' will be painted as a 'checkbox'.

Attaching a label to a cell

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 - 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

Default labels

The name of the region the cell is in is added as a default label. For example, all cells in the body region have the label BODY by default.

Layers and configuration objects

Configuration information is contributed by individual layers. When a layer is added to the stack it contributes relevant configuration via the AbstractLayer.addConfiguration() method. For example, when the SelectionLayer is added it contributes selection styling via the DefaultSelectionLayerConfiguration.

In order to contribute configuration information you need to:

  1. Implement the IConfiguration interface. It is usually easier to override one of the default configuration objects.
  2. Disable default configuration. This is done by setting 'autoconfigure' to false on the layer constructor. By default a layer will automatically add its default configuration.
  3. Add your configuration to the layer using the AbstractLayer.addConfiguration() method.

When the grid initializes it invokes your configuration object. At this point you can make entries in the IConfigRegistry and the UiBindingRegistry. These are global objects held by NatTable.

Back to the top