I am working on a project and need to have multiple datatables on the same page. As mentioned on the website, I tried two methods of using following mentioned code:
$('table.display').DataTable();
$('#example').DataTable();
This displays datatables on first table, but not on the second one. As said on their website and also in some questions answered on StackOverflow, the first one should work no matter how many tables we use.
The HTML code is as mentioned below:
<table id="renewallist" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Insured's Name</th>
<th>Department</th>
<th>Policy No.</th>
<th>From</th>
<th>To</th>
<th>S.I.</th>
<th>Premium</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<th>Insured's Name</th>
<th>Department</th>
<th>Policy No.</th>
<th>From</th>
<th>To</th>
<th>S.I.</th>
<th>Premium</th>
<th>Description</th>
<th></th>
</tr>
</tfoot>
<tbody>
<?php foreach ($allpol as $key => $value) { ?>
<tr>
<td><?php echo $value->firmname; ?></td>
<td><?php echo $value->deptname; ?></td>
<td class="brkwrd"><?php echo $value->polno; ?></td>
<td class="w75"><?php echo date("d-m-y", strtotime($value->startdate)); ?></td>
<td class="w75"><?php echo date("d-m-y", strtotime($value->enddate)); ?></td>
<td>Rs. <?php echo $value->si; ?></td>
<td>Rs. <?php echo $value->premium; ?></td>
<td class="brkwrd"><?php echo $value->description; ?></td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target=".pol" onclick='getpolinfo(<?php echo $value->polid; ?>)'>View Info</button></td>
</tr>
<?php } ?>
</tbody>
</table>
All positive suggestions are appreciated.
Thank You in advance...
$('table.display').DataTable(), see this example. Most likely you're not initializing your tables correctly or table becomes available after you perform initialization.