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

[Bug] filterColumn does not work on individual column search #52

Closed
yajra opened this issue May 17, 2015 · 3 comments
Closed

[Bug] filterColumn does not work on individual column search #52

yajra opened this issue May 17, 2015 · 3 comments
Labels

Comments

@yajra
Copy link
Owner

yajra commented May 17, 2015

as reported by @sameerpanjwani on issue #43

@yajra yajra added the bug label May 17, 2015
@yajra yajra closed this as completed in 5ce6680 May 19, 2015
@sameerpanjwani
Copy link

Still doesn't work

public function getMultiFilterSelectData()
    {
        $users = User::select([  \DB::raw("CONCAT(users.id,'-',users.id) as user_id"), 'name', 'email', 'created_at', 'updated_at']);

        $dt =  Datatables::of($users);

        // Global search function
        if ($keyword = \Request::get('search')['value']) {
            // override users.name global search

            // override users.id global search - demo for concat
            $dt ->filterColumn('user_id', 'whereRaw', "CONCAT(users.id,'-',users.id) like ?", ["%$keyword%"]);
        }

        return $dt->make(true);
    }

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'where clause' (SQL: select count() as aggregate from (select '1' as row_count from users where LOWER(user_id) LIKE %101%) count_row_table)*

@yajra
Copy link
Owner Author

yajra commented May 19, 2015

It's because you are using global search and not column search. You should use something like below:

        $users = User::select([
            DB::raw("CONCAT(users.id,'-',users.id) as user_id"),
            'name',
            'email',
            'created_at',
            'updated_at']);
        $datatables = Datatables::of($users);

        $columns = $request->get('columns');
        foreach ($columns as $column) {
            if ($column['searchable'] == 'true' and $column['search']['value'] != '' and $column['name'] == 'user_id') {
                $datatables->filterColumn('user_id', 'whereRaw', "CONCAT(users.id,'-',users.id) like ?", ["%{$column['search']['value']}%"]);
            }
        }

        return $datatables->make(true);

On your code, filterColumn is not triggered.

@sameerpanjwani
Copy link

Oh ok, I didn't realize that. Sorry, my mistake.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants