Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concat not word #12

Open
wong89 opened this issue Oct 6, 2016 · 1 comment
Open

concat not word #12

wong89 opened this issue Oct 6, 2016 · 1 comment

Comments

@wong89
Copy link

wong89 commented Oct 6, 2016

concat query not work this example concat work but this function concat not suport where clause...thanks :-)

https://datatables.net/forums/discussion/32686/server-side-with-joins

@j0ssGZ
Copy link

j0ssGZ commented Jan 12, 2017

I solved it with the next change in filter function. Basically if the search string is multiple, splits it and loop the words:

static function filter ( $request, $columns, &$bindings, $isJoin = false )
    {
        $globalSearch = array();
        $columnSearch = array();
        $dtColumns = SSP::pluck( $columns, 'dt' );


        if ( isset($request['search']) && $request['search']['value'] != '' ) {
            $str = $request['search']['value'];

            if ( count( preg_split( '/\s+/', $request['search']['value'] ) ) > 1 ) {
                $fWords = preg_split( '/\s+/', $request['search']['value'] );

                foreach ( $fWords as $str ) {
                    for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
                        $requestColumn = $request['columns'][$i];
                        $columnIdx = array_search( $requestColumn['data'], $dtColumns );
                        $column = $columns[ $columnIdx ];

                        if ( $requestColumn['searchable'] == 'true' ) {
                            $binding = SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                            $globalSearch[] = ($isJoin) ? $column['db']." LIKE ".$binding : "`".$column['db']."` LIKE ".$binding;
                        }
                    }
                }
            } else {
                for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
                    $requestColumn = $request['columns'][$i];
                    $columnIdx = array_search( $requestColumn['data'], $dtColumns );
                    $column = $columns[ $columnIdx ];

                    if ( $requestColumn['searchable'] == 'true' ) {
                        $binding = SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                        $globalSearch[] = ($isJoin) ? $column['db']." LIKE ".$binding : "`".$column['db']."` LIKE ".$binding;
                    }
                }
            }
        }

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants