Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
Usando DataTables en Laravel sin aJax - No hay datos disponibles en la tabla

Tengo una vista regular de Laravel que representa una tabla. Cuando trato de usar Datatables en él, representa la tabla pero parece querer formatearla antes de que la tabla se represente realmente. Estoy confundido porque, cuando se representa la vista, el trabajo del lado del servidor ya está hecho. Lo único que está haciendo es renderizar la tabla con el objeto pasado desde el controlador.

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

Esto es con lo que termino:

ingrese la descripción de la imagen aquí

No quiero usar AJAX para formar mi tabla. He usado muchas instancias de Vanilla PHP y DataTables antes donde funciona bien. Agradecería cualquier sugerencia sobre lo que me puede estar perdiendo.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Ha colocado <tbody> en el lugar equivocado. <tbody> debe usarse debajo de </thead> .

Aquí está el ejemplo de código:

 <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>
over 4 years ago · Santiago Trujillo Report

0

Agregue la etiqueta tr dentro de la etiqueta thead . El bucle foreach debe estar en la etiqueta tbody de apertura y cierre.

Debe tener un aspecto como este:

 <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>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!