php - 在没有 aJax 的情况下在 Laravel 中使用 DataTables - 表中没有可用数据

标签 php jquery laravel datatables

我有一个常规的 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(); 
})

这就是我最终得到的结果:

enter image description here

我不想使用 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/

相关文章:

php - 如何正确清理 html post 以保存在 mysql 中

php - $_GET、$_SESSION 和 XMLHttpRequest 的问题

php - 将所有可能的 Set 值存储在一个数组中?

php - curl 导致 SSL : unable to get local issuer certificate

php - 如何使用 Laravel 显示匹配记录字段的用户?

jquery - 根据 div 中的对象数量调整 div 内容的大小

jquery - 根据另一个日期选择器实例更改 jQuery 日期选择器中显示的月份

window.getSelection() 函数的 jquery 替代函数

laravel - 如何从 "belongsTo"加载关系?

Laravel 5 将字符串主键作为整数返回