Update column comparators after column reorder [message #1714792] |
Mon, 16 November 2015 11:56  |
Eclipse User |
|
|
|
Hello,
I followed the tutorial on https://www.eclipse.org/nattable/documentation.php?page=sorting to enable sorting in my table. Everything works fine when the table is initially created.
My table also supports DnD of columns and here is the problem:
When a user has reordered the columns via DnD, how can I update the comparator of each column?
Example
A Table has 3 columns: String, Integer, Boolean (in this order).
Now the user moves the Boolean column in front of the Integer column.
Now the comparator of the Integer column must me moved to the third column too and the comparator of the Boolean column must be moved to the second column.
How can I achieve this? Comparators are registered via column index and do not get updated by default. I also tried to update them by myself by clearing the column overrides and set them again. But this does not seem to have any effect.
Any ideas?
Regards
Tommy
|
|
|
|
Re: Update column comparators after column reorder [message #1714851 is a reply to message #1714798] |
Tue, 17 November 2015 04:41   |
Eclipse User |
|
|
|
Hello Dirk, thanks for your answer.
I already add the labels to the DataLayer of the column header. Here is how my ColumnHeaderLayerStack (shortened) looks like:
IDataProvider headerDataProvider = new ColumnHeaderDataProvider();
DataLayer columnHeaderDataLayer = new DataLayer(headerDataProvider);
// enable sorting
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
for (int i = 0; i < getColumns().size(); i++) {
labelAccumulator.registerColumnOverrides(i, ColumnComparator.CUSTOM_COMPARATOR_LABEL);
}
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new ColumnComparator(),
DisplayMode.NORMAL, ColumnComparator.CUSTOM_COMPARATOR_LABEL);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
SortHeaderLayer<IGeoDataRow> sortHeaderLayer = new SortHeaderLayer<>(
columnHeaderLayer,
new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer),
false);
setUnderlyingLayer(sortHeaderLayer);
Am I doing something wrong here?
|
|
|
|
|
|
|
|
|
Re: Update column comparators after column reorder [message #1715100 is a reply to message #1714936] |
Thu, 19 November 2015 03:59  |
Eclipse User |
|
|
|
So I removed the ColumnReorderLayer and added only one Comparator for each column that can handle every data type. So I don't have to move them when reordering columns manually. I also added my own SortConfiguration which also imitates the behavior of columns where a NullComparator has been added.
That works well for me.
Thanks for all your hints and explanations.
|
|
|
Powered by
FUDForum. Page generated in 0.06470 seconds