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.

Related Posts

JQuery Remove duplicate elements

JQuery Remove duplicate elements – Easy method

JQuery Remove duplicate elements: It’s very easy to remove duplicate elements from a list using jQuery. Demo: Let’s say we have below list: Here multiple duplicate values…

jQuery sorting by price

jQuery sorting by price – Easy method(jQuery 3.x)

In this example let’s check how to do jQuery sorting by price in an easy way. Demo: Its a very important feature in ecommerce platforms to do…

sum of datatable column

Calculate sum of Datatable columns and display in footer – Easy method with sum()

In this example let’s check how to calculate sum of datatable columns (multiple columns) and display the same in footer. In some cases we may need to…

css counter

Automatic serial number in HTML table – CSS Counter

Here we will discuss how to get serial number automatically in a column in the html table. CSS counters are “variables” maintained by CSS whose values can…

jquery toggle

jQuery Toggle() Method

How to do jquery Toggle() method to show/hide onclick The jQuery toggle() method is used to toggle between the hide() and show() method. It shows the hidden…

jquery validation

jQuery validation for confirm password

How to validate password and confirm password using jQuery validation plugin ? Earlier we have discussed how to validate a form validation with jQuery validate plugin, in…

Leave a Reply

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