我有一个常规的 Laravel View 来渲染表格。当我尝试在其上使用数据表时,它确实渲染了表格,但它似乎想在实际渲染表格之前对其进行格式化。我很困惑,因为在渲染 View 时,服务器端工作已经完成。它所做的唯一事情就是使用从 Controller 传递的对象来渲染表格。
<table id="stockmovement" class="table table-hover" style="width:100%">
<tbody>
<thead>
<th>Material</th>
<th>Tipo</th>
<th>Quantidade</th>
<th>Valor total</th>
<th>Data</th>
<th>Ordem</th>
<th colspan="3"></th>
</thead>
@foreach($ordercontents as $ordercontent)
<tr>
<td>{{ $ordercontent->material_name }}</td>
<td>{{ $ordercontent->type }}</td>
<td>{{ $ordercontent->oc_weight }}</td>
<td>{{ number_format($ordercontent->oc_weight * $ordercontent->material_price, 2) }}</td>
<td>{{ $ordercontent->order_date }}</td>
<td>{{ $ordercontent->order_name }}</td>
</tr>
@endforeach
</tbody>
</table>
$(document).ready(function() {
$('#stockmovement').DataTable();
})
这就是我最终得到的结果:
我不想使用 AJAX 来构建我的表格。我之前使用过很多普通的 PHP 和 DataTables 实例,它们运行得很好。如果有人指出我可能遗漏的内容,我将不胜感激。
最佳答案
您已放置<tbody>
在错误的地方。 <tbody>
应该在</thead>
下使用.
下面是代码示例:
<table id="stockmovement" class="table table-hover" style="width:100%">
<thead>
<th>Material</th>
<th>Tipo</th>
<th>Quantidade</th>
<th>Valor total</th>
<th>Data</th>
<th>Ordem</th>
</thead>
<tbody>
@foreach($ordercontents as $ordercontent)
<tr>
<td>{{ $ordercontent->material_name }}</td>
<td>{{ $ordercontent->type }}</td>
<td>{{ $ordercontent->oc_weight }}</td>
<td>{{ number_format($ordercontent->oc_weight * $ordercontent->material_price, 2) }}</td>
<td>{{ $ordercontent->order_date }}</td>
<td>{{ $ordercontent->order_name }}</td>
</tr>
@endforeach
</tbody>
</table>
关于php - 在没有 aJax 的情况下在 Laravel 中使用 DataTables - 表中没有可用数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70816669/