【发布时间】:2020-06-12 06:12:23
【问题描述】:
我正在使用 Yajra 数据表包来加载记录。但是我在整页而不是在特定表格上获取记录。我不明白错误在哪里。
查看文件
<table id="clientsTable" class="table table-bordered table-striped dataTable">
<thead>
<tr>
<th>#</th>
<th>First name</th>
<!--<th>Last name</th>-->
<th>Mobile number</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
</table>
脚本文件
$(document).ready(function($) {
$('#menu-clients').addClass('active');
$('#clientsTable').DataTable({
processing: true,
serverSide: true,
"bDestroy": true,
"bAutoWidth": false,
ajax:{
url : '/clients',
method: 'get',
},
columns:[
{ data: 'DT_RowIndex'},
{ data: 'first_name', name: 'first_name'},
{ data: 'mobile_no', name: 'mobile_no'},
{ data: 'email', name: 'email'},
{ data: 'actions', name: 'actions'},
]
});
});
路由文件
Route::resource('/clients', 'ClientsController');
控制器
public function index()
{
$data = DB::table('clients')->orderBy('id', 'desc')->get();
return Datatables::of($data)
->addColumn('actions','buttons.clients')
->rawColumns(['actions'])
->addIndexColumn()
->make(true);
}
在网络选项卡中响应
{draw: 0, recordsTotal: 166, recordsFiltered: 166, data: [,…], input: []}
draw: 0
recordsTotal: 166
recordsFiltered: 166
data: [,…]
[0 … 99]
[100 … 165]
input: []
【问题讨论】:
-
在控制台中显示错误 - 调用 ajax 时的网络
-
我已通过网络响应编辑了我的问题
标签: jquery mysql laravel yajra-datatable