Laravel-datatables: Many-to-Many relationship is not searchable.

Created on 26 Apr 2016  路  7Comments  路  Source: yajra/laravel-datatables

Basically, I would like to say thank you for your effort to write this package which is really useful.

I have 3 tables which are many-to-many relationship.
-users
-user_role
-roles

I have tried addColumn('roles',function(){});. It totally worked, but unfortunately it's not searchable on the roles column.

Did I miss something? Or there is another to do so? Please instruct me.

enhancement

All 7 comments

@tepafril, can you try this PR and use eager loading demo for ref?

On the other hand, you can also use the join demo for more stable solution.

Thanks!

The demo of eager loading is not many-to-many relationship. I think it's one-to-many relationship.
I have tried:
$users = User::with('roles')->select('users.*');
return Datatables::of($users)
->make(true);
But still i couldn't search 'roles' column. And yes, it's displaying on the screen.

Yes, the demo is one-to-many but the concept is the same and you need to use PR #490. Forgot to add the link to the PR above.

Work like a charm! Thank you so much 馃憤

@tepafril, what approach did you use? Join statements or using the PR? Will merge the PR if that fixes your issue. Thanks!

@yajra here is my code snippet:

//controller
public function ApiGetAll(){
$transactions = Transaction::with(array('stocks','user'));
return Datatables::of($transactions)->make(true);
}
?>

// hide the column and enable searching
// doing so to enable searching
columns: [
{ data: 'stocks.en_name', name: 'stocks.en_name',searchable:true },
]

I just merged and released PR #490 on v6.11.0. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sangnguyenplus picture sangnguyenplus  路  3Comments

vipin733 picture vipin733  路  3Comments

jackrsantana picture jackrsantana  路  3Comments

techguydev picture techguydev  路  3Comments

SGarridoDev picture SGarridoDev  路  3Comments