jQuery datatable插件具有按日期从数据库中选择的数据时,无法使用。但是,如果表中没有数据,它就可以正常工作。这里一些代码
从控制器中的数据库表中选择所有数据:
$inbound['inbound'] = DB::table('REPORT_INBOUND')
->where('regdate', '=', date('Y-m-d', strtotime("2019-05-21")))
->get();
return view('/traffic', $inbound, $outbound);
我确实复制粘贴了必要的脚本,例如:
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<table id="ahhhaa" width="90%" class="table table-striped table-bordered table-hover display">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>RegDate</th>
<th>HPMN Code</th>
<th>Country</th>
<th>HPMN Name</th>
</tr>
</head>
<tbody>
@foreach($inbound as $value)
<tr class="table table-hover">
<td>{{ $value->id }}</td>
<td>{{ $value->regdate }}</td>
<td>{{ $value->hpmn_code }}</td>
<td>{{ $value->country }}</td>
<td>{{ $value->hpmn_name }}</td>
@endforeach
</tbody>
</table>
$(document).ready(function () {
$('#ahhhaa').DataTable()
});
有什么错误吗?
答案 0 :(得分:0)
可能是因为您没有关闭您的thead
。
修复此问题,如果未解决,请发表评论。
<table id="ahhhaa" width="90%" class="table table-striped table-bordered table-hover
display">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>RegDate</th>
<th>HPMN Code</th>
<th>Country</th>
<th>HPMN Name</th>
</tr>
</thead><!-- Add this Line -->
<tbody>
loop...
</tbody>
希望这行得通!
答案 1 :(得分:0)
返回包含数据的视图页面:
return view('folder/file_name')->with($inbound);
答案 2 :(得分:0)
更改表的ID。否则,laravel不会将表标识为数据表。
<table id="datatable-buttons" class="table table-responsive">