on 10-12-2007 1:59 PM
I implemented the TableSorter for NW 2004 as described on SDN. It works quite good with most of my columns. But I have some columns which contain primitive data types (boolean in this case). This causes a ClassCast exception in TableSorter, in this code section:
public int compare(Object o1, Object o2)
{
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return +1;
return ((Comparable) o1).compareTo((Comparable) o2);
}
Does anybody know, how it is possible to sort data with primitive datatypes?
Thanks in advance!
Martin
Hi Martin
private static final Comparator DEFAULT = new Comparator() {
/**
Compares the given objects according to the ordering imposed by the first
ones <code>compareTo(Object)</code> function. Furthermore, <code>null</code>
is treated to be less than any object.
@see java.lang.Comparable#compareTo(java.lang.Object)
@see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object o1, Object o2) {
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return +1;
if (o1 instanceof Boolean && o2 instanceof Boolean)
return o1.toString().compareTo(o2.toString()); // false < true
return ((Comparable) o1).compareTo((Comparable) o2);
}
};
May be the above code snippet helps you that to sort the boolean values if at all
present in your table column.
Regards
Kalyan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
what you can do is substitute the string value for the boolean value, hence the sort will work fine.
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.