Monthly Archives: October 2016

Simple datatables.net code

This is just a basic code to use datatables.

Important components in the code:

  1. include of js, css on top
  2. declaring ‘thead’ tag
  3. declaring ‘id’ of the table to be same as called in js at the bottom
  4. include js script at the bottom

or can refer here for code

 

<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>