javasortingnattablenebula

How to sort config labels in natTable as well? (Is there a simple way to get relative coordinates from a nattable?)


I'm using the natTable's config label as an identifier to color each cell in the table.

config Labels are assigned to the table in absolute coordinates.

However, when sorting, the corresponding label is in absolute coordinates, so when the values ​​are sorted, I want the labels to be sorted as well. What should I do in this case?

Can I change the config label to relative coordinates?

If possible, I'd like to know how.


Solution

  • You should not rely on column and row numbers but on some real information. The feature you are talking about is named "conditional styling" and the cell coordinates are not a very good condition. Especially because of the behavior you describe.

    https://www.vogella.com/tutorials/NatTable/article.html#architecture_labels

    You could add the label accumulator on the DataLayer, which is mostly the only layer where index == position. You could also implement a index-position-transformation in you accumulator. But dependent on the way you implemented sorting, the underlying list structure might change, e.g. when using the GlazedLists SortedList. In that way there is no way to identify the cell coordinate reliably.