我有一個呈現表格的常規 Laravel 視圖。當我嘗試在其上使用 Datatables 時,它會渲染表格,但它似乎想在表格實際渲染之前對其進行格式化。我很困惑,因為在呈現視圖時,服務器端的作業已經完成。它唯一要做的就是使用從控制器傳遞的物件來渲染表格。
<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 實體。我將不勝感激任何關于我可能遺漏的指示。
uj5u.com熱心網友回復:
你放<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>
uj5u.com熱心網友回復:
tr在標簽內添加thead標簽。foreach 回圈應該在開始和結束tbody標記中。
它應該如下所示:
<table id="stockmovement" class="table table-hover" style="width:100%">
<thead>
<tr>
<th>Material</th>
<th>Tipo</th>
<th>Quantidade</th>
<th>Valor total</th>
<th>Data</th>
<th>Ordem</th>
</tr>
</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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/419098.html
標籤:
