jQuery Datatable – Easy Steps

jquery datatable

jQuery Datatable – Easy Steps

Here is simple example to create jQuery Datatable.

jQuery Datatable organizes data in grid like format of rows and columns. It is very organized, interactive and intutive. jQuery provides plugin to create datatables very easily. Let’s check how jQuery datatables are done.

FILES to include :

CSS :

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.css">

jQuery :-

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.js"></script>

It is mandatory to have these three files

HTML

Here is the full code for creating a jquery datatable.

<!DOCTYPE html>
<html>
<head>
	<title>Datatable</title>
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.css">
  	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
	<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.js"></script>

</head>
<body style="padding: 100px;">
	<table id="table_id" class="display">
	    <thead>
	        <tr>
	            <th>Column 1</th>
	            <th>Column 2</th>
	            <th>Column 3</th>
	            <th>Column 4</th>
	            <th>Column 5</th>
	            <th>Column 6</th>
	        </tr>
	    </thead>
	    <tbody>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
			<tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	        </tr>
	        <tr>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Row 1 Data 2</td>
	            <td>Row 1 Data 1</td>
	            <td>Qwerty</td>
	        </tr>
	    </tbody>
	</table>
</body>
<script type="text/javascript">
	$(document).ready( function () {
	    $('#table_id').DataTable();
	} );
</script>
</html>

Script

<script type="text/javascript">
     $(document).ready( function () {
	 $('#table_id').DataTable();
     });
</script>

This script will initialize datatable on table id table_id.

Hope this example helps you to create jquery datatable easily.

Here is a link to calculate sum of datatable columns and display in footer – Click me.

To get more information on Datatable please goto Datatables.

Leave a Reply

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

Back To Top