I’m using Glazed Lists to sort and filter a JXTable.
How can I sort on out-of-table values? That is, I would like to be able to format column values in my own way, yet sort on raw values.
My current relevant code:
EventList<Foo> foos = GlazedLists.threadSafeList(new BasicEventList<Foo>());
foos.add(new Foo("bar", 5000000));
ObservableElementList.Connector<Foo> fooConnector = GlazedLists.beanConnector(Foo.class);
EventList<Foo> observedFoos = new ObservableElementList<Foo>(foos, fooConnector);
SortedList<Foo> sortedFoos = new SortedList<Foo>(observedFoos, null);
EventTableModel tableModel = new EventTableModel(sortedFoos, someTableFormat);
JXTable t = new JXTable(tableModel);
new TableComparatorChooser<Foo>(t, sortedFoos, false);
In this example, I would like to format the value in the second column as 5.0M rather than 5000000, but if I use this value in the list, it won’t sort properly.
Thanks in advance.
Maybe you have to disable the JXTable Sorting, so it does not interfere with the GL sorting? Something like:
… and then install GlazedLists TableComparatorChooser on the table like:
Or do you mean, you want to format 5000000 as 5.0M in the table, not in the List? Then you would only have to implement your TableFormat’s
to return the 5.0M representation of 5000000.
… could well be, that I did not fully understand the problem and these answers are not helping 😉
EDIT: Runnable example…
Look at the code in the main method – especially the code with the START-END comment.
I made my own very simple example, but you should understand, what I mean.
Oh… sorry for the naming of classes/variables/… 😉