Individual Column Searching for Multiple values

Individual Column Searching for Multiple values

mmcnair80mmcnair80 Posts: 83Questions: 21Answers: 7

Is there a way to use the Text Inputs to search for multiple values?

For example, I have a table that has a State column. Is there a way to do a search for both AL and AZ? Like typing "AL ,AZ" or "AL ; AZ"?

Here is how I'm initializing the Text Inputs:

api.columns('.dt-filter-text').every(function ()
{
    var that = this;

    $('input', this.footer()).on('keyup change', function ()
    {
        if (that.search() !== this.value)
        {
            that
              .search(this.value)
              .draw();
        }
    });
});

Answers

  • mmcnair80mmcnair80 Posts: 83Questions: 21Answers: 7

    I got this to work by modifying my FilterSort.class.php file (a modified version of the ssp.class.php) so that the filter function now has this for the Individual column filtering:

    // Individual column filtering
    if ( isset( $request['columns'] ) )
    {
        for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ )
        {
            $requestColumn = $request['columns'][$i];
            $columnIdx = array_search( "[" .$requestColumn['data']. "]", $dtColumns );
            $column = $columns[ $columnIdx ];
            $str = $requestColumn['search']['value'];
            if ( $requestColumn['searchable'] == 'true' && $str != '' )
             {
                 if(substr_count($str,";") > 0)
                 {
                     $WhereStr = strpos($str,";");
                     $SearchColumn = "([" .$column['db']. "] like '%" . substr($str,0,$WhereStr). "%'";
                     for($x = 1;$x < substr_count($str,";");$x++)
                     {
                         $SearchColumn = $SearchColumn. " or [" .$column['db']. "] like '%" . substr($str,$WhereStr+1,strpos($str,";",$WhereStr+1) - ($WhereStr+1)). "%'";
                         $WhereStr = strpos($str,";",$WhereStr+1);
                     }
                     $SearchColumn = $SearchColumn. " or [" .$column['db']. "] like '%" . substr($str,$WhereStr+1). "%')";
                     error_log(date("Y/m/d h:i:sa")." SearchColumn:  " .$SearchColumn. "\n",3,"C:\Temp\LogPHP.txt");
                     $columnSearch[] = $SearchColumn;
                 }
                 else
                 {
                    $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                    $columnSearch[] = "[" .$column['db']."] LIKE ".$binding;
                 }
            }
        }
    }
    

    It might not be the most elegant, but it does work!
    It looks for a semi-colon and separates out the values based on that.

This discussion has been closed.