google-code-export / google-web-toolkit-incubator

Automatically exported from code.google.com/p/google-web-toolkit-incubator
0 stars 1 forks source link

ColumnSorter API improvements #186

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If you want to see this feature/enhancement implemented, please star this
issue by clicking on the star in the upper left hand corner of this page.

== Enhancement Description ==

Currently there is one default implementation of SortableGrid.ColumnSorter
available. And DefaultColumnSorter has private access mode. So, I need to
implement new Sorter from scratch if I need to add new functionality. For
example, I want to sort content of columns as Integers. 

You can see that in quicksort() method comparison performs with compareTo()
method:

DOM.getInnerText(tdElems[i]).compareTo(pivot)
DOM.getInnerText(tdElems[k]).compareTo(pivot)

So, my suggestion is to make DefaultColumnSorter public and add new
constructor which will accept Comparator interface. And this comparator
will be used in quicksort().

Thanks.

Original issue reported on code.google.com by devun...@gmail.com on 8 Nov 2008 at 8:14

GoogleCodeExporter commented 9 years ago
Note that you also need to update SortableGrid. I'm using this implementation:

public class CustomFixedWidthGrid extends FixedWidthGrid {
    private Map<Integer, ColumnSorter> column2columnSorter = new HashMap<Integer,
ColumnSorter>();

    public void setColumnSorter(int column, ColumnSorter columnSorter) {
        column2columnSorter.put(column, columnSorter);
    }

    /**
     * Sort the grid according to the specified column.
     *
     * @param column    the column to sort
     * @param ascending sort the column in ascending order
     * @throws IndexOutOfBoundsException
     */
    public void sortColumn(int column, boolean ascending) {
        // Verify the column bounds
        if (column < 0) {
            throw new IndexOutOfBoundsException(
                    "Cannot access a column with a negative index: " + column);
        }

        if (column >= numColumns) {
            throw new IndexOutOfBoundsException("Column index: " + column
                    + ", Column size: " + numColumns);
        }

        // Add the sorting to the list of sorted columns
        getColumnSortList().add(new TableModel.ColumnSortInfo(column, ascending));

        ColumnSorter columnSorter = column2columnSorter.get(column);

        if (columnSorter == null) {
            columnSorter = getColumnSorter(true);
        }

        // Use the onSort method to actually sort the column
        columnSorter.onSortColumn(this, getColumnSortList(),
                new ColumnSorterCallback());
    }
}

Original comment by devun...@gmail.com on 9 Nov 2008 at 3:09

GoogleCodeExporter commented 9 years ago
I'd prefer to add column sort capabilities to dedicated typed ColumnDefinition 
classes.
These typed column sorters could be used in ScrollTable in the same way as I 
apply 
the filters.

Original comment by daniel.florey@gmail.com on 11 Nov 2008 at 10:01

GoogleCodeExporter commented 9 years ago

Original comment by ecc%google.com@gtempaccount.com on 1 Dec 2008 at 5:49

GoogleCodeExporter commented 9 years ago
I've tried to use the code above, but I fail to instansiate ColumnSorterCallback
since this constructor is protected.

Original comment by trond.an...@gmail.com on 2 Sep 2009 at 2:32