Sunday, March 30, 2014

How to @Override Comparator to make the Column in CellTable sort based on Integer not based on String (GWT)?

Ok, I got a Table with a list of No.

No  1  2  5  10  20  

If i set columnSortHandler for the No column using String like this:

columnSortHandler.setComparator(noColumn, new Comparator<String[]>() {          @Override          public int compare(String[] o1, String[] o2) {              if (o1==o2) {                    return 0;              }                  if (o1 != null) {                    return (o2 != null) ? o1[0].compareTo(o2[0]) : 1;              }              return -1;          }      });  

Then it won't sort like integer but like String. Ex: it will sort like this:

No  1  10  2  20  5  

Then it is not correct.

So tried:

 columnSortHandler.setComparator(noColumn, new Comparator<String[]>() {          @Override          public int compare(String[] o1, String[] o2) {              if (o1==o2) {                    return 0;              }                  if (o1 != null) {                    return (o2 != null) ? Integer.parseInt(o1[0]).compareTo(Integer.parseInt(o2[0]) : 1;              }              return -1;          }      });  

But compareTo does not apply for Integer.

So my question is

How to @Override Comparator to make the Column in CellTable sort based on Integer not based on String (GWT)?

(also http://stackoverflow.com/questions/22743000/how-to-override-comparator-to-make-the-column-in-celltable-sort-based-on-intege)


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment