Compound Filtering in JXTable
844961Mar 4 2011 — edited Mar 7 2011Hello Everyone,
I am struggling here trying to use a compound Filter (one condition or the other) in my JXTable. I could sucessfully filter my table using only one filter, as below:
Filter[] filters = new Filter[] {
new PatternFilter(textToFilter, java.util.regex.Pattern.CASE_INSENSITIVE, colNumber), // regex, matchflags, column
};
FilterPipeline pipeline = new FilterPipeline(filters);
jxtable.setFilters(pipeline);
However I could not use the above implementation to filter in two condiitions. I tried another approach as the following:
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(jxtable.getModel());
RowFilter<TableModel, Object> firstFiler = null;
RowFilter<TableModel, Object> secondFilter = null;
java.util.List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>>();
RowFilter<TableModel, Object> compoundRowFilter = null;
try {
firstFiler = RowFilter.regexFilter("(?i)"+textToFilter1, colNumber);
secondFilter = RowFilter.regexFilter("(?i)"+textToFilter2, colNumber);
filters.add(firstFiler);
filters.add(secondFilter);
compoundRowFilter = RowFilter.orFilter(filters); // you may also choose the OR filter
} catch (java.util.regex.PatternSyntaxException e) {
e.printStackTrace();
}
sorter.setRowFilter(compoundRowFilter);
jxtable.setRowSorter(sorter);
But it did not work at all, actually the table was displayed normally, without any filtering.
Any help is appreciated.
Thanks in advance