In previous article I have discussed how to fetch data from api and show in table and in this article I am going to discuss how we can use dataTable plugin in our table to implement some advance feature for table like search functionality for searching table data and pagination. If you don’t know about data table plugin then don’t worry because here I am going to tell each and every step for implementing dataTable plugin for jquery.

Introduction to jquery dataTable plugin

DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, built upon the foundations of progressive enhancement, that adds all of these advanced features to any HTML table. With this plugin you can add so many functionalities like pagination and searching and so on. Today we are going to implement the pagination and search functionality in our table. After applying this our table look like the following table.

jquery datatable plugin

In above image we are simply applying pagination and search functionality with jquery dataTable plugin but before that we are fetching the data from api and show in the form of table and for giving styles to our table I am using the bootstrap very common library for css.

Jquery dataTable plugin Example

For making the table like in the above picture we have divided our code in three files which is index.html which contains the html file, contains CDN link for bootstrap and dataTable plugin and one table tag with id. Then we have one script file which contains the code for fetching the data from api and code of jquery for jquery dataTable plugin and last one is css file which is not required which is just optional.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src=""></script>
    <link rel="stylesheet" href="" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <!-- data table plugin used first css -->
    <link rel="stylesheet" href="//">
    <!--data table plugin used second js-->
    <script src="//"></script>
    <link rel="stylesheet" href="style.css">
    <title>How to fetch data from api and show data in table with jquery dataTable plugin</title>
    <div id="padding">
    <table id="myTable" class="table table-success">
    <script src="script.js"></script>


$(document).ready( function () {
    const xhttp=new XMLHttpRequest()"GET","",true)
    if(this.status==200 && this.readyState==4)
        const data=JSON.parse(this.responseText);

        let header="<thead>"
        let table="<tr>";
        let body="<tbody>"
        for(let i=0;i<data.length;i++)
            let row="<tr>";
        body= body+"</tbody>";
        header = header + body;




    margin-left: 50px;
    margin-right: 50px;
    padding-top: 5px;
    background-color: aquamarine;

Source code

Above is the whole code through we can implement the jquery datatable plugin in our code. This plugin is literally very good to use as it provides client side pagination and searching functionality that is also good for small application where you have limited amount of data. Instead of this if you want to download the whole code then you can download it from given below.