AMIR HOSSEIN SOROURI AMIR HOSSEIN SOROURI - 4 months ago 8
jQuery Question

Is it possible to use php to write in the tables and already use datatable to make tables optimize?

I have more than one table in one view and i use jquery to make them hide and show.i have the array $works which contains arrays of works.each array contains data that are the rows of each table.
also i use Datatable to optimize my tables using pagination and be able to search.

but it seems

datatables
doesn't know blade language and php.
i set the datatable to show me in each page 10 row of the table.but when my table has more than 10 rows it shows me all the rows and shows:

Showing 1 to 1 of 1 entries


the above expression.

<div class="col-md-offset-1 col-md-7">
<?php $i = 0 ?>
@foreach($works as $work)
<!--<div class="panel navbar-inverse">
<div class="panel-heading panel-amir">
<p href="#">Current Works</p>
</div>-->
<?php $i+=1; ?>
<div id="{{$dep->id}}" class="panel-body testimonial" data-index="{{$i}}">

<table cellpadding="0" cellspacing="0" border="0" class="table table-hover TABLE mytable" id="example" data-index="{{$i}}">
<thead style="text-align: center">
<th style="text-align: center">User Works</th>
<th style="text-align: center">Title</th>
<th style="text-align: center">Due Date</th>
<th style="text-align: center">Description</th>
</thead>

@foreach($work as $var)
<tbody>

<tr>
<td class="col-md-2">
<img class="img-circle img-responsive" src="{{ URL::to('/') }}/images/amir.png">
</td>
<td class="col-md-2">
alaki
</td>
<td class="col-md-2">
alaki
</td>
<td class="col-md-6">
alaki
</td>
</tr>

</tbody>
@endforeach
</table>
</div>
@endforeach




enter image description here

Is there any idea what should i do to design my page correctly????

Answer

dataTables only supports one <tbody> section at a time. You have

@foreach($work as $var)
   <tbody>
     ....
   </tbody>
@endforeach

causing multiple <tbody>'s, thats why you get Showing 1 to 1 of 1 entries. Iterate over rows instead :

<tbody>
  @foreach($work as $var)
    <tr>
      <td class="col-md-2">
    ...
    </tr>
  @endforeach
</tbody>

By doing that, I am sure you will get the correct number of rows in the info-section, and the table will paginate as expected.