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:"
Maybe try using this trick on your js:
columns : [
{ data: 'name', name: 'fname' },
{ data: 'name', name: 'lname', visible: false },
...
Or use filterColumn api.
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).
ok its solved using https://datatables.yajrabox.com/fluent/joins. Thanks
Most helpful comment
Maybe try using this trick on your js:
Or use filterColumn api.