sjs994 / google-web-toolkit-incubator

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

Should enable a different strategy in sorting (eg. by date, or other ways) #342

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What version of gwt and gwt-incubator are you using?
gwt-incubator-20100204-r1747.jar 

What OS and browser are you using?
chrome, ff 3.6

Do you see this error in hosted mode, web mode, or both?
no

(If possible, please include a test case that shows the problem)
        dataTable.setColumnSorter(new SortableGrid.ColumnSorter() {

            @Override
            public void onSortColumn(SortableGrid grid, ColumnSortList sortList,
ColumnSorterCallback callback) {
                // Get the primary column and sort order
                int column = sortList.getPrimaryColumn();
                boolean ascending = sortList.isPrimaryAscending();

                // Get all of the cell elements
                SelectionGridCellFormatter formatter =
grid.getSelectionGridCellFormatter();
                int rowCount = grid.getRowCount();
                List<Element> tdElems = new ArrayList<Element>(rowCount);
                for (int i = 0; i < rowCount; i++) {

/*formatter.getRawElement has protected access: not visible here*/
tdElems.add(formatter.getRawElement(i, column));
                }

                // Sort the cell elements
                if (ascending) {
                    Collections.sort(tdElems, new Comparator<Element>() {
                        public int compare(Element o1, Element o2) {
                            return o1.getInnerText().compareTo(o2.getInnerText());
                        }
                    });
                } else {
                    Collections.sort(tdElems, new Comparator<Element>() {
                        public int compare(Element o1, Element o2) {
                            return o2.getInnerText().compareTo(o1.getInnerText());
                        }
                    });
                }

                // Convert tdElems to trElems, reversing if needed
                Element[] trElems = new Element[rowCount];
                for (int i = 0; i < rowCount; i++) {
                    trElems[i] = DOM.getParent(tdElems.get(i));
                }

                // Use the callback to complete the sorting
                callback.onSortingComplete(trElems);
            }
        });

Hopefully using the test case you have generously provided, what steps will
reproduce the problem? 
1. dates sorted by alphabetical order

What is the expected output? What do you see instead?
a real date sorting (without having to change the date format) 

Workaround if you have one:
Maybe do an html content with a hidden div that contains an exploitable
value for the sort (very tricky)

Please provide any additional information below,  and thank you for taking
the time and effort to report this issue, as good issue reports are
critical for our quest to make GWT's new widgets and libraries shine.
Ideally the table should use a renderer to show the cells, we could then
have exploitable objects to compare with traditional comparators. Then a
simple interface implementation for each column that defines the "public
int compare( Object o1, Object o2 ) {}" (knowing that the asc desc param
can invert the result).

Best Regards,
Zied Hamdi
http://www.into-i.fr

Original issue reported on code.google.com by zHa...@gmail.com on 2 Mar 2010 at 3:31

GoogleCodeExporter commented 8 years ago
I have a partial solution that consists to reconstruct the table if I need to 
sort on
a column that has a special handling. There's still a problem on indicating 
which
column is sorted visually 

The part I tried was this on line 98:
                    /* this part doesn't work */
                    ColumnSortList columnSortList = new ColumnSortList();
                    columnSortList.add(new TableModelHelper.ColumnSortInfo(column, ascending));
                    dataTable.setColumnSortList(columnSortList);

Best Regards,
Zied Hamdi
http://www.into-i.fr

Original comment by zHa...@gmail.com on 2 Mar 2010 at 5:38

Attachments: