我第一次使用Bllim Laravel。
我没有收到任何错误消息,但既没有能够填充数据表中的数据,我得到数据表,但它没有数据。查询工作正常,我可以看到其中的数据,但它没有传递给Datatable或不是数据表能够读取的格式
在此处发布代码:
控制器
public function listAjax() {
$posts = DB::table('newspaper')->select('id', 'no_of_pages', 'date', 'publishing_time', 'status');
return Datatables::of($posts, true)->make();}
查看
<table id="newspaperList" class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>No of pages</th>
<th>Date</th>
<th>Publishing time</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$("#newspaperList").dataTable({
"processing": true,
"serverSide": true,
"ajax": "http://localhost:88/epaperlaravel/public/ep-admin/newspaper/listajax",
"order": [[1, 'desc']],
"columnDefs": [{//this prevents errors if the data is null
"targets": "_all",
"defaultContent": ""
}],
"columns": [
//title will auto-generate th columns
{"data": "id", "title": "Id", "orderable": true, "searchable": false},
{"data": "no_of_pages", "title": "Name", "orderable": true, "searchable": true},
{"data": "date", "title": "Username", "orderable": true, "searchable": true},
{"data": "publishing_time", "title": "Email", "orderable": true, "searchable": true},
{"data": "status", "title": "Created", "orderable": true, "searchable": true},
]
});
});
路线
Route::get('ep-admin/newspaper/listajax', array('as' => 'articlesajax', 'uses' => 'NewspaperController@listAjax'));
我哪里出错了?
答案 0 :(得分:-1)
显示数据需要这么多脚本:
$('#dataTables-example').DataTable( {
bProcessing: true,
bServerSide: true,
dom: "Tfrtip",
sAjaxSource: "{{ URL::to('/work/showusers') }}",
aaSorting : [[ 0, "desc" ]],
"aoColumns": [
{ 'sWidth': '60px' },
{ 'sWidth': '130px', 'sClass': 'center' },
{ 'sWidth': '180px', 'sClass': 'center' },
{ 'sWidth': '60px', 'sClass': 'center' },
],
tableTools: {
sRowSelect: "os",
aButtons: [
{ sExtends: "editor_create", editor: editor },
{ sExtends: "editor_edit", editor: editor },
{ sExtends: "editor_remove", editor: editor }
]
},
language: {
processing: "Traitement en cours...",
search: "Rechercher :",
lengthMenu: "Afficher _MENU_ éléments",
info: "Affichage de l'élement _START_ à _END_ sur _TOTAL_ éléments",
infoEmpty: "Affichage de l'élement 0 à 0 sur 0 éléments",
infoFiltered: "(filtré de _MAX_ éléments au total)",
infoPostFix: "",
loadingRecords: "Chargement en cours...",
zeroRecords: "Aucun élément à afficher",
emptyTable: "Aucune donnée disponible dans le tableau",
paginate: {
first: "Premier",
previous: "Précédent",
next: "Suivant",
last: "Dernier"
},
aria: {
sortAscending: ": activer pour trier la colonne par ordre croissant",
sortDescending: ": activer pour trier la colonne par ordre décroissant"
}
}
} );
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-hover" id="dataTables-example">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Password</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Password</th>
</tr>
</tfoot>
</table>