jsm

net/sf/jsm/table/filters/jsmRegExFilter.js

Summary

No overview generated for 'net/sf/jsm/table/filters/jsmRegExFilter.js'


Class Summary
JsmRegExFilter A filter implementation checking if the cell value matches the regular expression

/**
 * Creates a new JsmRegExFilter object
 * @class A filter implementation checking if the cell value matches the regular expression
 * @constructor
 * @param {String} columnIdxOrName The column idx or name
 * @param {String|Array of Strings} value The regEx the cell has to match; If an array of regExes is passed one of the regExes has to match
 * @param {boolean} ignoreCase Ignore case
 */ 
  function JsmRegExFilter(columnIdxOrName, value, ignoreCase) {
  	this.columnIdxOrName = columnIdxOrName;
  	this.value = value;
  	this.ignoreCase = ignoreCase;
  } 
  JsmRegExFilter.prototype.className="JsmRegExFilter";  
  
  /** checks if this row is valid or if it should be filtered out
 	* @param {JsmTr} The table row
 	* @return {boolean}
  	*/     
  JsmRegExFilter.prototype.isValidRow = function(tr) {
  	var cellValue = tr.getCell(this.columnIdxOrName).getValue().replace(/'/g, "\\'"); // escape any '
  	//if it is a string put in into an array
  	if (typeof this.value == 'string') {
  		var tempValue = new Array();
  		tempValue.push(this.value);
  		this.value = tempValue;
  	}  	  	
  	for (i=0;i<this.value.length;i++) {
		var value = this.value[i].replace(/\//g, "\\/"); //escape any /
	 	if (this.ignoreCase) {
		 	regEx = "'" + cellValue + "'.search(/" + value + "/i)"; 		
	 	} else {
	 		regEx = "'" + cellValue + "'.search(/" + value + "/)";
	 	}
	 	if (eval(regEx) != -1) {return true;} 				
  	}  	
  	return false;
  } 
  
  /** Sets the column to filter on
 	* @param {int/String} columnIdxOrName The column name or index
 	* @return this
  	*/     
  JsmRegExFilter.prototype.setColumn = function(columnIdxOrName) {
  	this.columnIdxOrName = columnIdxOrName;  
  	return this;  	
  }      
  
  /** Sets the value to filter against
 	* @param {String} value
 	* @return this
  	*/     
  JsmRegExFilter.prototype.setValue = function(value) {
  	this.value = value;  
  	return this;  	
  }   
  
  /** Specifies if the case should be ignored
 	* @param {boolean} ignoreCase
 	* @return this
  	*/     
  JsmRegExFilter.prototype.setIgnoreCase = function(ignoreCase) {
  	this.ignoreCase = ignoreCase;  
  	return this;  	
  }   
  
  /** Clones this JsmRegExFilter
  * @return {JsmRegExFilter}
  */
  JsmRegExFilter.prototype.clone = function() {
	var clonedObject = new JsmRegExFilter();
   	//TODO is it sufficient to copy the Array or do we have to iterate and copy each entry
   	clonedObject._attributes = this._attributes;
   	clonedObject._metaData = this._metaData;   
   	clonedObject.value = this.value; 
   	clonedObject.ignoreCase = this.ignoreCase; 
   	clonedObject.columnIdxOrName = this.columnIdxOrName;    	   	  		
   	return clonedObject;	
  }       

jsm

Documentation generated by JSDoc on Tue Sep 26 08:42:57 2006