0
我使用yajra的datatable和laravel數據表。Laravel和jquery數據表
我有我的看法如下:
employeeTable = $('#employeeTable').DataTable({
deferLoading: 0,
serverSide: true,
processing: true,
ajax: {
url: "{!! route('ajaxlistemployee') !!}",
type: "POST",
data: ajaxData,
dataType: "JSON",
dataSrc: function (json) {
console.log(json);
return json.data;
}
},
columns: [
{ data: 'id', name: 'id'},
{ data: 'name', name: 'name'},
{ data: 'manager_id', name: 'manager_id'},
{ data: 'manager_name', name: 'manager_name'},
{ data: 'is_manager', name: 'is_manager'},
{ data: 'region', name: 'region'},
{ data: 'country', name: 'country'},
{ data: 'domain', name: 'domain'},
{ data: 'subdomain', name: 'subdomain'},
{ data: 'management_code', name: 'management_code'},
{ data: 'job_role', name: 'job_role'},
{ data: 'employee_type', name: 'employee_type'},
],
columnDefs: [
{
"targets": [0, 2], "visible": false, "searchable": false
}
]
});
我也有我的倉庫:
public function getEmployeeList($where = null){
$employee = \DB::table('employee AS E')
->select(
'E.id',
'E.name',
'E.manager_id',
'M.name AS manager_name',
'E.is_manager',
'E.region',
'E.country',
'E.domain',
'E.subdomain',
'E.management_code',
'E.job_role',
'E.employee_type'
)->join('employee AS M', 'E.manager_id', '=', 'M.id');
if (!empty($where['manager']))
{
$employee->where(function ($query) use ($where) {
foreach ($where['manager'] as $w)
{
$query->orWhere('E.manager_id',$w);
}
});
}
return $employee;
}
我有我的Ajaxcontroller:
public function getAjaxListEmployee(Request $request){
$input = $request->all();
$return = $this->employeeRepository->getEmployeeList($input);
$data = Datatables::of($return)->make(true);
return $data;
}
這是很簡單,除了搜索和排序不起作用之外,一切正在運行。
我不明白爲什麼,我嘗試了很多不同的配置。
但沒有人努力讓我得到我需要的東西。
開放的開發工具,看你做了什麼錯誤。 – linuxartisan
@Richard檢查控制檯中的錯誤並將其發佈到此處 –