Share

ThinWire Ajax RIA Framework

Tracker: Bugs

5 setSortOrder and setSortComparator do not work in DropDown - ID: 1838466
Last Update: Comment added ( pra9ma )


The setSortOrder and the setSortComparator functions on a gridbox column
have no effect on the displayed sorted order for data in the drop down. In
addition, the data in a dropdown is listed in the reverse order to which it
was added.

The code that was used to demonstrate this behavior is:

<Setup GridBox>
...

GridBox.Column col1 = new GridBox.Column();
col1.setName("Name");
gb.getColumns().add(col1);

col1.setSortOrder(GridBox.Column.SortOrder.ASC);
col1.setSortComparator(new Comparator()
{
public int compare(Object o1, Object o2)
{
System.out.println(o1.toString());
System.out.println(o2.toString());
return o2.toString().compareTo(o1.toString());
}
});

<Add data to grid...>

I have tried changing various values (SortOrder.NONE, SortOrder.DESC), and
turning on and off the allowSort value for the grid but it has no effect on
the rendered drop down.


Kevin Self ( kself ) - 2007-11-26 05:48

5

Closed

Wont Fix

Joshua Gertzen

Server Generated Error/Exception

v1.2 RC2

Public


Comment ( 1 )




Date: 2008-01-02 20:54
Sender: pra9maProject Admin


I created DropDownSortTest in the apps/test/trunk ThinWire Tests
application in order to flush this out. However, after looking closely at
this, it looks like everything is working as designed and there are a few
issues in the code you provided: 1) If you want to have a GridBox start
out sorted, then you should call setSortOrder AFTER setSortComparator. The
framework currently resets the sortOrder property to
GridBox.Column.SortOrder.NONE upon changing the sortComparator. 2) The
Comparator you outlined compares item 2 against item 1 and that is why the
content is listed in reverse order. As per the Comparator.compare
documentation, compare should return: a negative integer, zero, or a
positive integer as the first argument is less than, equal to, or greater
than the second.

Additionally, it's worth mentioning that only 1 column may be sorted by at
a time in a GridBox. This is because the intention of
sortComparator/sortOrder is to control the visual sorting of columns by the
user. It's not really intended to sort the data in one or more columns for
the purpose of initial display. For that, you should execute a comparator
against a given column using java.util.Collections.sort:

java.util.Collections.sort(col1, new Comparator() {
public int compare(Object o1, Object o2) {
return o1.toString().compareTo(o2.toString());
}
});

And as a final note, I did check in a minor change to GridBox.Column to
make the previously private member DEFAULT_SORT_COMPARTOR public so that
now you can just do the following if you want to leverage the default
string sort:

java.util.Collections.sort(col1, GridBox.Column.DEFAULT_SORT_COMPARTOR);




Log in to comment.

Attached File

No Files Currently Attached

Changes ( 5 )

Field Old Value Date By
status_id Open 2008-01-02 20:54 pra9ma
resolution_id None 2008-01-02 20:54 pra9ma
category_id None 2008-01-02 20:54 pra9ma
assigned_to nobody 2008-01-02 20:54 pra9ma
close_date - 2008-01-02 20:54 pra9ma