Your code didn't work, beside it got the problem for non-digit string. Ex: 
if i sort this list:
  Full slide-out QWERTY
  Full QWERTY
  Full QWERTY
  Numeric with T9 multimedia
  Soft QWERTY
  Slide-out QWERTY
  Full QWERTY
  Full QWERTY
  Slide-out QWERTY
 
It still didn't show the correct result.

Note: for this table, I have to add the columns dynamically, so i use 
List<String> for column, not just String.


On Monday, April 22, 2013 7:19:41 PM UTC+10, PhiLho wrote:
>
> On 22/04/2013 10:44, Henry wrote: 
> > I got these code: 
> > ///****************************///////////// 
> >       ListHandler<List<String>> columnSortHandler = new 
> ListHandler<List<String>>( 
> >                      list); 
> >              columnSortHandler.setComparator(nameColumn, 
> >                      new Comparator<List<String>>() { 
> >                        public int compare(List<String> o1, List<String> 
> o2) { 
> >                          if (o1 == o2) { 
> >                            return 0; 
> >                          } 
> > 
> >                          // Compare the name columns. 
> >                          if (o1 != null) { 
> >                            return (o2 != null) ? 
> o1.get(0).compareTo(o2.get(0)) : 1; 
> >                          } 
> >                          return -1; 
> >                        } 
> >                      }); 
> > 
> >                  table.addColumnSortHandler(columnSortHandler); 
> > 
> > ///****************************///////////// 
> [...] 
> > Is there anything wrong with the code above? 
>
> public int compare(List<String> o1, List<String> o2) { 
>      return o1.get(0).compareTo(o2.get(0)); 
> } 
>
> But in this case, the default comparator provided by GWT will do the same 
> job. 
> I did that for a numerical comparison of values with units, for example: 
>
> @Override 
> public int compare(List<String> o1, List<String> o2) 
> { 
>      String v1 = o1.get(columnIndex); 
>      String v2 = o2.get(columnIndex); 
>      double d1 = DataService.parseValue(v1); 
>      double d2 = DataService.parseValue(v2); 
>      if (d1 == 0 && d2 == 0) 
>          return v1.compareTo(v2); // String comparison 
>      return Double.compare(d1, d2); 
> } 
>
> The DataService.parseValue() parses the double at the start of the string, 
> stopping on the 
> unit symbol. 
> The columnIndex is a member of my Comparator, since we do the same sorting 
> for all columns. 
>
> -- 
> Philippe Lhoste 
> --  (near) Paris -- France 
> --  http://Phi.Lho.free.fr 
> --  --  --  --  --  --  --  --  --  --  --  --  --  -- 
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to