php – convert normal html table into datatable-ThrowExceptions

Exception or error:

I want too convert normal table in html to datatable so that i can get more options like

  1. sorting

  2. pagination

  3. searching

How can i do this?
this is my code for table.

 <table id="payment">    
    <thead class="bg-danger">
        <th>S NO</th>
        <th>Date</th>
        <th>Voucher No</th>
    </thead>
    <tbody>
        <tr>
            <td> 1 </td>
            <td> 16/03/2020</td>
            <td> 12345</td>
        </tr>
        <tr>
            <td> 2 </td>
            <td> 17/03/2020</td>
            <td> 98765</td>
        </tr>
    </tbody>
</table>
How to solve:

Just go to the main web-page and explore it.

Below a simple example of possible DataTable with your table code.

$(()=>{
    $('#payment').DataTable();
})
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>  
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/> 
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.20/css/dataTables.bootstrap.min.css"/>

<table id="payment">    
    <thead class="bg-danger">
        <th style="width:200px;">S NO</th>
        <th style="width:200px;">Date</th>
        <th style="width:200px;">Voucher No</th>
    </thead>
    <tbody>
        <tr>
            <td> 1 </td>
            <td> 16/03/2020</td>
            <td> 12345</td>
        </tr>
        <tr>
            <td> 2 </td>
            <td> 17/03/2020</td>
            <td> 98765</td>
        </tr>
    </tbody>
</table>
      

Leave a Reply

Your email address will not be published. Required fields are marked *