Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatablejs : Search not working for JOIN table result

I have integrated Datatable (https://datatables.net) for the listing of records in the Admin Panel. All default functionality (Searching, Sorting) was working fine when I was fetching data/result from single table.

But when I require joining two tables, I am facing below error because of Datatable auto search for every column that you named in your JS code.

Error:

Column not found: - Unknown column

JS code:

{ data: "iBookingId","width": "3%","bSortable":false},(=> From booking)<br>
{ data: "vName","width": "10%","bSortable":false},(=> From users)<br>
{ data: "email","width": "15%","bSortable":false},(=> From users)<br>
{ data: "dDate","width": "7%","bSortable":false},(=> From booking)<br>

How can I resolve that? Any suggestion?

like image 512
Krupal Patel Avatar asked Jan 22 '26 00:01

Krupal Patel


1 Answers

After many efforts, I found the solution.

Simply, you just need to pass new attribute "name" along with data so datatable will search for that column.

{ data: "iBookingId" ,"width": "3%","bSortable":false},
{ data: "vName",name: 'users.vName' ,"width": "10%","bSortable":false},
{ data: "email",name: 'users.email' ,"width": "15%","bSortable":false},
{ data: "dDate" ,"width": "7%","bSortable":false},

PS: Don't apply searchable: false as a patch. :P

like image 146
Krupal Patel Avatar answered Jan 24 '26 12:01

Krupal Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!