Multi-Column table filtering

edited December 2016 in Share Your Work

Hi,

I was wondering whether there was a simple way to filter a table with multiple column criteria?

so far, my current work-around is to create the following class:

public class FilterTable extends Table {

public FilterTable() {
    super();
}


public FilterTable(Iterable<TableRow> rows) {
    super(rows);
}

public FilterTable filter(String field, String value) {

    FilterTable result = new FilterTable(this.findRows(value, field));
    for (int i = 0; i < getColumnCount(); i++) {
        result.addColumn(getColumnTitle(i), getColumnType(i));
    }

    return result;
}

public FilterTable filterLike(String field, String value) {

    FilterTable result = new FilterTable(matchRows(value, field));
    for (int i = 0; i < getColumnCount(); i++) {
        result.addColumn(getColumnTitle(i), getColumnType(i));
    }

    return result;
}

}

and then to call it like this:

  for(TableRow row:myFilterTable.filter("animal", "leopard").filter("age", "10").rows()){
      // do something.
}

Thanks.

Sign In or Register to comment.