make Server side column filtering more powerful in simple steps

make Server side column filtering more powerful in simple steps

ffalzoabiffalzoabi Posts: 1Questions: 0Answers: 0
edited December 2023 in Free community support

hello

I apologize for my bad English

I wanted to share with you a simple add-on but with high performance. I benefited from it a lot and noticed that most users search for it in the ssp.class.php file.

The addition concerns column filtering
as u know that column filtering is by defalut goes like this

col LIKE %val%

The addition will allow you to search in other options such as

= and > and <> and <

By adding a simple function to the file and modifying only three lines

Copy the function and paste it into the class in the ssp.class.php file

//Copy the function and paste it into the class in the ssp.class.php file

static function CustomSearch ($string) {
if (mb_strlen($string, 'UTF-8') > 1 && (substr($string, 0, 1) == ">" || substr($string, 0, 1) == "<" || substr ($string, 0, 1) == "!" || substr($string, 0, 1) == "=")) {
if($string[0] == "!") { $ArrOp = "!="; } else { $ArrOp = $string[0]; }
$ArrStr = substr($string, 1);
} else {
$ArrOp = 'LIKE';
$ArrStr = '%'.$string.'%';
}
return array($ArrOp,$ArrStr);
}

//Replace the following lines in the same file
$str = $requestColumn['search']['value'];
//by this
$str = self::CustomSearch ($requestColumn['search']['value']) ?? '';
$op = $str[0];
$str = $str[1];

//and this
$binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$columnSearch[] = "`".$column['db']."` LIKE ".$binding;
//by this
$binding = self::bind( $bindings, $str, PDO::PARAM_STR );
$columnSearch[] = "`".$column['db']."` ".$op." ".$binding;

Now after the modification

You can search in any column in the following way
<9
!val
=122

or just simple val to use the defalut "LIKE"

I ask you to correct linguistic or other errors, or add more explain for the code and you can develop the code as well, as it is available to everyone without conditions.

Hope, someone finds it useful

My English is bad and I don't know how to use advanced programs to share the code

I thought a lot and decided to write this topic and leave it to you

thank u all
fahad

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi Fahad,

    That's awesome, thank you very much for sharing that with us. I'm sure others will benefit.

    Allan

Sign In or Register to comment.