Google Tag Manager

2009/03/02

aterai

Reset RowFilter before sorting

Code

final RowFilter < TableModel, Integer > filter = new RowFilter () {
  @Override
  public boolean include(Entry < ? extends TableModel, ? extends Integer > entry) {
    int vidx = table.convertRowIndexToView(entry.getIdentifier());
    return vidx < USER_SPECIFIED_NUMBER_OF_ROWS;
  }
};
final TableRowSorter sorter = new TableRowSorter(model) {
  @Override
  public void toggleSortOrder(int column) {
    if(check.isSelected()) {
      //((AbstractTableModel)table.getModel()).fireTableDataChanged();
      allRowsChanged();
      super.toggleSortOrder(column);
      allRowsChanged();
    }else{
      super.toggleSortOrder(column);
    }
  }
};
//final TableRowSorter sorter = new TableRowSorter < TableModel > (model) {
//  @Override
//  public void toggleSortOrder(int column) {
//    if(check.isSelected()) {
//      RowFilter < ? super TableModel, ? super Integer > f = getRowFilter();
//      setRowFilter(null);
//      super.toggleSortOrder(column);
//      setRowFilter(f);
//    }else{
//      super.toggleSortOrder(column);
//    }
//  }
//};
table.setRowSorter(sorter);
sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(1, SortOrder.DESCENDING)));

References

No comments:

Post a Comment