我试图使用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>
&#13;
我使用的是JQuery 3.2.1 请帮忙!
注入网址的数据来自下面的函数
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);
}
答案 0 :(得分:0)
这有帮助。谢谢@kaddath
$('.table-grid').DataTable({
serverSide: true,
processing: true,
ajax: { type:"GET", url: $('.table-grid').data('url') },
columns: [
{ "data": "created_at" },
{ "data":"username" },
{ "data":"package_amount" },
{ "data":"direct_id" },
{ "data":"register_by" },
{ "data":"action" }
],
答案 1 :(得分:0)
升级时遇到的问题
未捕获的TypeError:无法使用'in'运算符来搜索'length'in
(写入时)升级到最新的数据表,例如:1.10.19。
由数据表修复:带有jquery-rails(4.3.3)的1.10.19