1

I fix project which uses jide SortableTable. If table contains data only in English, then sorting works just fine. In case data is in mixed western European languages, sorting fails.

If i sort the data collections using Collator with strength "SECONDARY" it works fine.

The question is: how to make the SortableTable to sort data with SECONDARY collator strength or with custom comparator?

YuriR
  • 1,251
  • 3
  • 14
  • 26
  • I think that this is question for [JIDE Software Developer Forums](http://www.jidesoft.com/forum/), but in other hands sometimes user [jidesoft](http://stackoverflow.com/users/1029967/jidesoft) look here – mKorbel Feb 21 '12 at 21:42
  • I will try there if i get no help here. But it looks like stackoverflow's users know almost everything :) – YuriR Feb 22 '12 at 04:53
  • mKorbel:I found on JIDE forum similar thread. Hope it will bring me to the correct solution. Thank you. – YuriR Feb 23 '12 at 07:31

2 Answers2

2

JIDE's SortableTableModel uses ObjectComparatorManager to get the comparator. You can register your Collator (by default, we use PRIMARY collator)

Collator collator = Collator.getInstance(); collator.setStrength(Collator.SECONDARY);

ObjectComparatorManager.registerComparator(String.class, collator , new ComparatorContext("CollatorSecondary")); // "CollatorSecondary" could be any string that is unique in your app

Then in your SortableTableModel subclass, you return new ComparatorContext("CollatorSecondary") by overriding getColumnComparatorContext(int column) for the column.

Another quick way is to override SortableTableModel's getComparator(int column) if you just want this behavior in one table.

Last but not least, you may also need to call SortableTableModel's setAlwaysUseComparators(true) because for the performance consideration, we used the cell value's compareTo method if available without using a comparator.

jidesoft
  • 202
  • 1
  • 3
0

How about inheritance and polymorphism? You can subclass a new class from SortableTable and add custom behavior. And use its instance where you need SortableTable.

Dmytro Chyzhykov
  • 1,814
  • 1
  • 20
  • 17
  • Yes, it looks to be correct direction. I tried it already, but it is not clear what functions should i override. – YuriR Feb 22 '12 at 04:29
  • I suppose you should create a custom constructor for a subclass and init a custom comparator that is based on Collator. – Dmytro Chyzhykov Feb 22 '12 at 08:26