Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a custom ColumnSorter with ScrollTable (GWT-incubator)
    text
    copied!<p>I've implemented my custom column sorter which is used to sort the elements in my table.</p> <pre> class FileColumnSorter extends SortableGrid.ColumnSorter { @Override public void onSortColumn(SortableGrid sortableGrid, TableModelHelper.ColumnSortList columnSortList, SortableGrid.ColumnSorterCallback columnSorterCallback) .... } </pre> <p>When I initialize the FixedWidthGrid I do the following:</p> <pre> FixedWidthGrid dataTable = new FixedWidthGrid(rows, cols); dataTable.setSelectionPolicy(SelectionGrid.SelectionPolicy.ONE_ROW); dataTable.setColumnSorter(new FileColumnSorter()); </pre> <p>The scrolltable is initialized the following way:</p> <pre> FixedWidthFlexTable headerTable = createHeaderTable(); // Calling the lines described above FixedWidthGrid fileListGrid = createDataTable (currentDescriptorList.size(), 6); // Combine the components into a ScrollTable scrollTable = new ScrollTable(fileListGrid, headerTable); scrollTable.setSortPolicy(AbstractScrollTable.SortPolicy.SINGLE_CELL); scrollTable.setColumnSortable(0, false); scrollTable.setColumnSortable(1, true); scrollTable.setColumnSortable(2, true); scrollTable.setColumnSortable(3, true); scrollTable.setColumnSortable(4, true); scrollTable.setColumnSortable(5, false); </pre> <p>When I run the application, I get the built in sorting instead of my custom sorting. I've also tried to do the following:</p> <pre> ColumnSorter sorter = new FileColumnSorter(); FixedWidthGrid dataTable = new FixedWidthGrid(rows, cols) { @Override public ColumnSorter getColumnSorter() { return sorter; } }; </pre> <p>To ensure that my sorter get used, but I still get the same experience. </p> <p><strong>Update: Added the FileColumnSorter</strong></p> <pre><code>class FileColumnSorter extends SortableGrid.ColumnSorter { @Override public void onSortColumn(SortableGrid sortableGrid, TableModelHelper.ColumnSortList columnSortList, SortableGrid.ColumnSorterCallback columnSorterCallback) { final int column = columnSortList.getPrimaryColumn(); final Integer[] originalOrder = new Integer[sortableGrid.getRowCount()]; for (int i = 0; i &lt; originalOrder.length; i++) { originalOrder[i] = i; } Arrays.sort(originalOrder, new Comparator&lt;Integer&gt;() { public int compare(Integer first, Integer second) { Descriptor firstDesc = share.getCurrentDescriptors().get(first); Descriptor secondDesc = share.getCurrentDescriptors().get(second); if (firstDesc.getType().equals(secondDesc.getType())) { switch (column) { case 0: return firstDesc.compareTo(secondDesc); case 1: return firstDesc.getName().compareTo(secondDesc.getName()); case 2: return ((Long) firstDesc.getSize()).compareTo(secondDesc.getSize()); case 3: return firstDesc.getCreated().compareTo(secondDesc.getCreated()); case 4: return firstDesc.getModified().compareTo(secondDesc.getModified()); default: return firstDesc.compareTo(secondDesc); } } else { return firstDesc.getType() == Descriptor.FileItemType.FOLDER ? 1 : -1; } } }); int[] resultOrder = new int[originalOrder.length]; for (int i = 0; i &lt; originalOrder.length; i++) { if (columnSortList.isPrimaryAscending()) { resultOrder[i] = originalOrder[i]; } else { resultOrder[resultOrder.length - i - 1] = originalOrder[i]; } } columnSorterCallback.onSortingComplete(resultOrder); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload