HOW TO add new comparison operator for filtering fields?

Talk and info about common issues

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

administrator
Site Admin
Site Admin
Posts: 5992
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO add new comparison operator for filtering fields?

Postby administrator » Oct 29th, '12, 16:48

To add new comparison operator for filter fields you have to do following:

1. Open datagrid.class.php file and find there

Code: Select all

$this->arrFilteringOperators = array('=', '!=', '<', '<=', '>', '>=', 'like', '%like', 'like%', '%like%', 'not like');

and add here your new operator.

2. Find in datagrid.class.php following line of code:

Code: Select all

$output .= '<option value="not like"'.(($filter_operator == 'not like')? ' selected="selected"' : '').'>'.$this->lang['not_like'].'</option>';

and add after it your own option in the same format.

3. Find in datagrid.class.php following line of code:

Code: Select all

}else if($requested_filter_field_operator == '%like%'){
   $sqlViewTemp .= " $fldTableField ".substr($requested_filter_field_operator, 1, 4).' '.$comparison_type." '%".$separated_word."%'";
}

and add after it check for your new operator, something like:

Code: Select all

}else if($requested_filter_field_operator == 'MY_OPERATOR'){
   $sqlViewTemp .= " $fldTableField ".$requested_filter_field_operator.' '.$comparison_type." '%".$separated_word."%'";
}

Return to “ApPHP DataGrid {HOW TO}”