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

How to filter a concatenated result value in multi fields in Laravel 5.3 #970

Closed
hari-web opened this issue Feb 3, 2017 · 3 comments
Closed
Labels

Comments

@hari-web
Copy link

hari-web commented Feb 3, 2017

Hi,

In my datatable, I'm retrieving the name field as CONCAT(fname," ", "lname"). I have to search name field in the datatable and it should return matching with either fname or lname. Please let me know how to do this:

js code:

columns  : [
   			 { data: 'name', name: 'fname' }, //I have tried this also : ['fname','lname' ]
                --------------------

PHP code:

$users = User::leftJoin('address', 'address.user_id', '=', 'users.user_id') 
                    ->select([\DB::Raw(
                        'CONCAT(fname," ",lname) as name, CONCAT(country_code, "", mobile_number) as mobile_num, IF(status = 1, "Active", "Inactive") as status,
                        (SELECT count(subscription_id) FROM subscription WHERE subscription.user_id = users.user_id AND subscription.status IN (2,4)) as totalActivesubscription'

                        ), 'gender', 'city as address', 'city','users.user_id', 'email_id'])

                    ->where('users.role_id', '=', $aParam['role_id']);

            return Datatables::of($users)
                ->addColumn('actions', function ($users) {
                    return view('users.templates.user_action', [
                        'user' => $users
                        ])->render();
                })
            

            ->make(true);

System details:"

  • Operating System : Windows8, Linux
  • PHP Version : 5.6
  • Laravel Version : 5.3
  • Laravel-Datatables Version : latest
@yajra
Copy link
Owner

yajra commented Feb 3, 2017

Maybe try using this trick on your js:

columns  : [
   { data: 'name', name: 'fname' },
   { data: 'name', name: 'lname', visible: false },
...

Or use filterColumn api.

@yajra yajra added the question label Feb 3, 2017
@hari-web
Copy link
Author

hari-web commented Feb 3, 2017

by using filterColumn api it worked. Thank you.
But what if we need to search a field of another table (which joined in the main query).

@hari-web
Copy link
Author

hari-web commented Feb 4, 2017

ok its solved using https://datatables.yajrabox.com/fluent/joins. Thanks

@hari-web hari-web closed this as completed Feb 4, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 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