This is just a basic code to use datatables.
Important components in the code:
- include of js, css on top
- declaring ‘thead’ tag
- declaring ‘id’ of the table to be same as called in js at the bottom
- include js script at the bottom
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<h1>A List</h1>
<table id="myTable" class="display" cellspacing="0" border="1">
<thead>
<tr>
<th>org</th>
<th>session</th>
<th>total</th>
</tr>
</thead>
<?php
$counter = 0;
foreach ($branch_list as $row) {
?>
<tr>
<td><?php echo $row->orgname; ?></td>
<td><?php echo $row->sessionname; ?></td>
<td><?php echo $row->total_student; ?></td>
</tr>
<?php } ?>
</table>
<script>
$(document).ready(function() {
$('#myTable').DataTable();
} );
</script> |