首页 > 解决方案 > 当数据库中有数据时,数据表不起作用

问题描述

当 Jquery 数据表插件具有按日期从数据库中选择的数据时,它不起作用。但如果表中没有数据,它就可以工作。这里有一些代码

从控制器中的数据库表中选择所有数据:

$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()
});

有什么错误吗?

标签: phpjquerylaraveldatatable

解决方案


也许是因为你没有关闭你的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>

希望这有效!


推荐阅读