Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Sorting not proper for numeric values
Sorting not proper for numeric values [message #1774010] Mon, 09 October 2017 07:10 Go to next message
Gaurav Tripathi is currently offline Gaurav TripathiFriend
Messages: 41
Registered: September 2015
Member
Hi,

In NatTable, I have the column which contains 3 digits and 4 digit number.
I have used GlazedListsSortModel within my SortHeaderLayer and added SingleClickSortConfiguration.

So when I click on this header it is sorting 3 digits first and then 4 digits.

For example 200,500,400,1200,1100

After sorting it is showing like this :
1100,1200, 200 400, 500 instead of
200, 400, 500, 1100, 1200.

I am not able to catch why so happening?
Is there any solution for same?

Thanks
Re: Sorting not proper for numeric values [message #1774013 is a reply to message #1774010] Mon, 09 October 2017 08:00 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2624
Registered: July 2012
Senior Member
Are the numbers treated as Numbers or Strings? The sorting looks like a string sort and not a number sort.

By default the DefaultComparator is registered as SortConfigAttributes.SORT_COMPARATOR. This implementation checks for the Comparable interface and performs the compare either via the Comparable#compareTo() or compares the String representation if the objects are not Comparables. So either the object type is not correct or you need to register a custom comparator for that column.
Re: Sorting not proper for numeric values [message #1774018 is a reply to message #1774013] Mon, 09 October 2017 09:45 Go to previous message
Gaurav Tripathi is currently offline Gaurav TripathiFriend
Messages: 41
Registered: September 2015
Member
Thank you, Mr. Dirk. You were right as my data was in a string format and not integer due to which sorting was not happening properly. I converted it to Integer and it worked properly.
Thanks again for pointing out.
Previous Topic:Same column having combo-box with two different list
Next Topic:Strange column reorder behavior
Goto Forum:
  


Current Time: Fri Nov 16 19:48:52 GMT 2018

Powered by FUDForum. Page generated in 0.02544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top