Skip to content

concat not word #12

Open
Open
@wong89

Description

@wong89

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

Activity

j0ssGZ

j0ssGZ commented on Jan 12, 2017

@j0ssGZ

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @j0ssGZ@wong89

        Issue actions

          concat not word · Issue #12 · emran/ssp