Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package pt.webdetails.cda.utils;
 import  org.apache.commons.lang.StringUtils;

Provides server-side filtering akin to DataTables' bFilter option.
All search terms must have a hit in one of the columns for a match
public class DataTableFilter {
  private static final String TERM_SEPARATOR = " ";
  private String[] searchTerms;
  private int[] searchableColumns;

searchText space-separated list of search terms
searchableColumns columns indexes to search on
  public DataTableFilter(String searchTextint[] searchableColumns){
    if(searchableColumns == null || searchText == null){
      throw new IllegalArgumentException(DataTableFilter.class.getName() + " cannot have null arguments.");
    this. = searchableColumns;
    this. = StringUtils.split(searchText);
  public boolean rowContainsSearchTerms(TableModel tableint rowIndex){
    String[] columnValues = getRelevantColumns(tablerowIndex);
    for(String searchTerm : ) {
      boolean containsTerm = false;
      for(String valuecolumnValues){
          containsTerm = true;
      if(!containsTermreturn false;
    return true;
  private String[] getRelevantColumns(TableModel tableint rowIndex){
    String[] row = new String[.];
    for(int i=0; irow.lengthi++){
      Object rawValue = table.getValueAt(rowIndex[i]);
      row[i] = (rawValue == null) ? null : rawValue.toString();
    return row;
New to GrepCode? Check out our FAQ X