我一直在使用Laravel 5.2項目中的Datatables插件。Datatables不能處理5列或更少
我正在用jQuery和Ajax發佈表格。
這是我的HTML表:
<table id="entidadeTable" class="table">
<thead>
<tr>
<th>ID</th>
<th>Nome</th>
<th>Descrição</th>
<th>Ações</th>
</tr>
</thead>
</table>
此後,我由DataTable的實例表:
var entidadeTable = $('#entidadeTable').DataTable({
"language": {
"url":"//cdn.datatables.net/plugins/9dcbecd42ad/i18n/Portuguese.json"
},
"order": [[0, "desc"]],
"ajax": {
"method": "POST",
"url": "{{ route('getTabelaEntidades') }}",
"data": {_token: "{{ Session::token() }}"}
},
"columns": [
{"data": "id"},
{"data": "nome"},
{"data": "descricao"},
{"data": "actions"}
],
});
這是我的控制器代碼,也就是負責將數據獲取到數據表:
$entidades = Entidade::all();
return response()->json(['draw' => 1, 'recordsTotal' => $entidades->count(),
'recordsFiltered' => $entidades->count(), 'data' => $entidades]);
但我得到這個數據表錯誤:
https://www.datatables.net/manual/tech-notes/4
我只得到這個錯誤,如果我的表中有不到6列。 我試圖把超過5列在我的表之後,它的工作和錯誤消失
錯誤:
DataTables warning: table id=entidadeTable - Requested unknown parameter '4' for row 0, column 4. For more information about this error, please see http://datatables.net/tn/4
退房此[包(https://github.com/yajra/laravel-數據表)。它幫助你很多 –