Closed melzangelina closed 6 years ago
Try this code:
public function dataTable($query)
{
$dataTable = DB::table('competencies')
->join('competency_groups', 'competencies.competency_group_id', '=', 'competency_groups.id')
->select('competencies.*', 'competency_groups.name AS group_name')
->get();
return Datatables::of($dataTable)->addColumn('action', 'competencies.datatables_actions');
}
@putradongkal your code works. Thanks!!
How to custom query in datatables/ModelDataTable.php
Hi Yajra, may we custom query in ModelDataTable.php? I have CompetencyDataTable.php and I want to join Competency data with Competency Group. I try to change the query, but it gives me error "Method getQuery does not exist.". Where should I put the custom query if I use datatables/ModelDataTable.php? And can you give me example the right query for this case? I use Infyom Generator with datatables when build this.
This is the CompetencyController.php
When I access competency page, it render datatables which has CompetencyDataTable as parameter.
This is the original CompetencyDataTable.php
I try to change in query parameter in datatables
But everytime I run the code, it gives me error "Method getQuery does not exist."
System details
This is my system details