【发布时间】:2019-01-07 20:12:40
【问题描述】:
我正在尝试使用 Datatables 和 jquery 填充我的表,但是我一直收到错误
TypeError: cannot use 'in' operator to search for 'length' in 'created_at'
在我的控制台中。
我的桌子:
$(function () {
$('.table-grid').DataTable({
serverSide: true,
processing: true,
ajax: $('.table-grid').data('url'),
columns: [
'created_at',
'username',
'package_amount',
'direct_id',
'register_by',
'action',
],
responsive: true,
searchDelay: 1000,
});
});
<table class="table table-full table-full-small dt-responsive display nowrap table-grid" cellspacing="0" width="100%" role="grid" data-url="{{ route('admin.member.getList') }}">
<thead>
<tr>
<th data-id="created_at">Join Date</th>
<th data-id="username">Username</th>
<th data-id="package_amount">Package</th>
<th data-id="direct_id" data-orderable="false" data-searchable="false">Direct ID</th>
<th data-id="register_by">Registered By</th>
<th data-id="action" data-orderable="false" data-searchable="false">
Action
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
我正在使用 JQuery 3.2.1 请帮忙!
注入到url的数据来自下面的函数
public function findAll (DataTables $dataTable, $table=false) {
if (!$table) return $this->model->all();
else {
return $dataTable->eloquent($this->model->query())
->addColumn('action', function ($model) {
return view('admin.member.action')->with('model', $model);
})
->editColumn('direct', function ($model) {
if ($direct = $model->direct()) return $direct->username;
else return 'Member not found.';
})
->editColumn('package_amount', function ($model) {
return number_format($model->package_amount, 2);
})
->make(true);
}
【问题讨论】:
-
我们能否提供一个来自
data-url属性中注入的 URL 的示例数据? -
@Kaddath 我已经更新了这个问题。谢谢
标签: jquery datatables laravel-5.5