I am using JIDE grids Sorting and Autofiltering capability in Matlab. I have overridden the getColumnClass and filtering and sorting is working well for Integers, Double and String Columns (sorting numerically for numbers and lexically respectively for strings).
However, I am facing a major issues with Date columns. I have overridden getColumn class and defined as Date.class. But I think I have to define the format in which the dates (as in raw data) are being passed to Filtering and Sorting for it to understand the format and work properly.
I see default date format in JIDE Autofiltering is '07-Apr-2016'. I have tried converting my data to same format but no luck. If I try to filter the dates, it throws (Unknown Source) exception. I think it does not understand my date format. How can I define the date format when overriding the class for Date column?
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
java.util.Date cannot be cast to java.lang.String
at java.lang.String.compareTo(Unknown Source)
at com.jidesoft.filter.LessThanFilter.isValueFiltered(Unknown Source)
at com.jidesoft.grid.FilterableTableModel.shouldBeFiltered(Unknown Source)
Here is my TableModel class that overrides DefaultTableModel.
import javax.swing.table.*;
import java.util.Date;
class MyTableModel extends DefaultTableModel {
public MyTableModel(Object rowData[][], Object columnNames[]) {
super(rowData, columnNames);
}
@Override
public Class getColumnClass(int col) {
switch (col){
case 0:
return Integer.class;
case 1: case 2: case 9:
case 10: case 33:
return String.class;
case 3:
return Date.class;
default:
return Double.class;
}
}
@Override
public boolean isCellEditable(int row, int col) {
switch (col){
case 28: case 29: case 30: case 31: case 32:
return true;
default:
return false;
}
}
}