RowSelectionModel shows all Column Header cells

408 views Asked by At

I have created a NatTable with a RowSelectionModel and a RowSelectionProvider:

  dataProvider = new ListDataProvider<>(rowData, columnAccessor);
  bodyDataLayer = new DataLayer(dataProvider);
  glazedListEventsLayer = new GlazedListsEventLayer<>(bodyDataLayer, rowData);
  columnReorderLayer = new ColumnReorderLayer(glazedListEventsLayer);
  columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
  selectionLayer = new SelectionLayer(columnHideShowLayer);
  ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);

  selectionProvider = new RowSelectionProvider<>(selectionLayer, dataProvider, true);
  selectionLayer.setSelectionModel(new RowSelectionModel<>(selectionLayer, dataProvider, idAccessor, false));

Basically, the table does what I want it to do. There is but one exception:

The table looks like this:

Screenshot

As intended, the table shows the row as selected (1). Also it highlights the actually selected cell (2), which is very nice. But, it renders the whole table column header as selected (3). I don't want that. I want either not highlight the header cells at all, or (even better:) I'd like only the column header cell of the cursor-cell (2) to be highlighted.

I thought that maybe there is a configuration label attached to the column header cells which results in the highlighting (so I could just change the style for this kind of label to get rid of the highlighting), but COLUMN_HEADER is the only configuration label, I can see when debugging.

So, I am bit stuck now. What causes the header cells to be highlighted and how can I change this behavior? Is it possible to highlight only the header of the cursor cell (as is done with the selected row's cursor cell (2))?

1

There are 1 answers

0
Dirk Fauth On BEST ANSWER

It is not the label you need to check, for selection it is the DisplayMode. So to not render the column header highlighted if you select a row you need to register the same style configuration for DisplayMode.SELECT as you register for DisplayMode.NORMAL.

If you only want to highlight the selection anchor in the column header you will need to register a custom IConfigLabelAccumulator to the DataLayer of the column header that is connected to the SelectionLayer and adds a custom label in case the cell in the column header is in the same column as the selection anchor.

For only highlighting the selection anchor, there is no default in NatTable itself. Although it should be easy to add. Feel free to create an enhancement ticket for this and even contribute. :)