/** * Method to call when the model data has changed. For example, when a row has been added or removed. * <p> * Handles resorting the data (if table sorted) and making sure the table pagination is still correct. * </p> */ public void handleDataChanged() { // Apply sort (if required) if (isSorted()) { sort(getSortColumnIndex(), isSortAscending()); } setCurrentPage(getCurrentPage()); }
if (sortCol != getSortColumnIndex() || sortAsc != isSortAscending()) { sort(sortCol, sortAsc); setFocussed();
rowIndexMapping = model.sort(getSortColumnIndex(), isSortAscending()); getOrCreateComponentModel().rowIndexMapping = rowIndexMapping;
@Test public void testSortTable() { SimpleTableModel model = new SimpleTableModel(new String[][]{{"1"}, {"3"}, {"2"}}); model.setComparator(0, SimpleTableModel.COMPARABLE_COMPARATOR); WTable table = new WTable(); table.setSelectMode(WTable.SelectMode.SINGLE); table.setTableModel(new AdapterBasicTableModel(model)); table.addColumn(new WTableColumn("dummy", WText.class)); table.setLocked(true); setActiveContext(createUIContext()); // Sort table manually table.sort(0, true); Assert.assertTrue("Incorrect selection after sort method", table.isSorted()); Assert. assertEquals("Incorrect sort column after sort method", 0, table. getSortColumnIndex()); Assert.assertTrue("Incorrect sort direction after sort method", table.isSortAscending()); List<RowIdWrapper> rowIndices = table.getRepeater().getBeanList(); Assert.assertEquals("Incorrect sort", 3, rowIndices.size()); Assert.assertEquals("Incorrect sort", Integer.valueOf(0), rowIndices.get(0).getRowIndex(). get(0)); Assert.assertEquals("Incorrect sort", Integer.valueOf(2), rowIndices.get(1).getRowIndex(). get(0)); Assert.assertEquals("Incorrect sort", Integer.valueOf(1), rowIndices.get(2).getRowIndex(). get(0)); }
table.setLocked(true); Assert.assertEquals("should return colIndex set", index, table.getSortColumnIndex()); Assert.assertEquals("should return ascending set", ascending, table.isSortAscending()); Assert.assertTrue("should be set as sorted", table.isSorted()); Assert.assertEquals("should return colIndex set", index, table.getSortColumnIndex()); Assert.assertEquals("should return ascending set", ascending, table.isSortAscending()); Assert.assertTrue("should be set as sorted", table.isSorted()); Assert.assertEquals("should return colIndex set", index, table.getSortColumnIndex()); Assert.assertEquals("should return ascending set", ascending, table.isSortAscending()); Assert.assertTrue("should be set as sorted", table.isSorted()); Assert.assertEquals("should return colIndexAlt set", indexAlt, table.getSortColumnIndex()); Assert.assertEquals("should return ascendingAlt set", ascendingAlt, table.isSortAscending()); Assert.assertTrue("should be set as sorted", table.isSorted());
Assert.assertTrue("Incorrect selection after handleRequest", table.isSorted()); Assert.assertEquals("Incorrect sort column after handleRequest", 0, table. getSortColumnIndex()); Assert.assertTrue("Incorrect sort direction after handleRequest", table.isSortAscending());
int col = table.getSortColumnIndex(); boolean ascending = table.isSortAscending();