我在Datatables Package for Laravel之后在Laravel 5上使用get started guide,但结果是没有匹配的记录。当我手动检查ajax时,结果在json文件中有一个用户。
路线:
Route::get('/target' , [
'as' => 'targets', 'uses' => 'TargetController@show'
]);
Route::controller('datatables', 'TargetController', [
'anyData' => 'datatables.data',
'getIndex' => 'datatables',
]);
查看:
<script>
$(function() {
$('#targets-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('datatables.data') !!}',
columns: [
{ data: 'id', name: 'id' },
{ data: 'name', name: 'name' },
{ data: 'email', name: 'email' },
{ data: 'created_at', name: 'created_at' },
{ data: 'updated_at', name: 'updated_at' }
]
});
});
</script>
控制器:
public function show()
{
return view('targets');
}
public function anyData()
{
return Datatables::of(TUser::query())->make(true);
}
带有搜索和分页的数据表正常加载,问题只是数据加载。
检查数据表/数据页面的结果是:
{"draw":0,"recordsTotal":1,"recordsFiltered":1,"data":[{"id":1,"name":"saaaaaaa","email":"aaaaaa","remember_token":null,"created_at":"2016-02-03 13:00:01","updated_at":"2016-02-03 13:00:01"}],"queries":[{"query":"select count(*) as aggregate from (select '1' as \"row_count\" from \"users\") count_row_table","bindings":[],"time":1.75},{"query":"select * from \"users\"","bindings":[],"time":0.72}],"input":[]}