Bootstrap 5 Datatable : Ajax Pagination with Search and Sort —

in this tutorial, We’ll learn how to create a dynamic listing using bootstrap 5 based datatable with PHP and MySQL. I am using the jQuery AJAX method to get records from MySQL. I also integrated ajax based sorting and searching using jquery datatable.

jQuery DataTables is a very popular JavaScript library to convert simple HTML tables into the feature-rich grid.jQuery will help to get records from MySQL in an AJAX manner.

We will cover following functionality in this Datatable Tutorial:

  • Load data from the MySQL Database using PHP
  • Ajax based sorting into Datatable
  • Ajax based searching into the Datatable
  • Ajax Based pagination

jQuery Ajax Datatable Listing Using PHP and MySQL

In this tutorial, You will learn how to implement Ajax-based DataTables Listing Records, Pagination, Sorting and Searching.

There are following files will participate into his tutorial:

  • index.php: The main entry file of the project.
  • action.php: This file is used to define all actions.
  • Employee.php: This file will contains all action method.
  • partials/header.php: This file is header file of the project and include all css/js.

Created Header File

Created a header.php file under /partials folder and added below code into this file.We ll include all css and js files into the header.php file:

We’ll create common.js file later on in this tutorial.

Create Datatable HTML Listing

Create a index.php file and added a HTML table element with css styling, we'll also add header.php into the top of the index.php file.

Create Actions

We’ll define all actions with method details and added below code into the action.php file:

Javascript file for AJAX Operation

We ll create common.js file into the js/ folder.

dt-employee is the html table id, where the jquery datatable functionality will apply.

Define Action Method for Listing Records

The action has been defined, Now Added below code into the Employee.php file to get all records based on action.


We have created an Html listing data using Ajax from MySQL. Also, Applied datatable on that table to create a full feature-rich grid. We have also Added server-side sorting and searching data based on input user search string. All the functionality is ajax based so the page is not refreshed at the time of listing, searching, and sorting.

Originally published at on September 4, 2021.




Hey, I am Parvez Alam. A software developer since 2009. I am a programming addict. I love learning and sharing knowledge.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parvez Alam

Parvez Alam

Hey, I am Parvez Alam. A software developer since 2009. I am a programming addict. I love learning and sharing knowledge.

More from Medium

What is PHP Framework Symfony? Explained for executives | Accesto BlogWelcome to our

Show a CMS Page in frontend through XML-Magento 2

Convert array to string in PHP 7 —

How to get the full URL of a page in PHP