Bootstrap 5 Datatable : Ajax Pagination with Search and Sort — Phpflow.com

Parvez Alam
2 min readSep 4, 2021

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.

Conclusion:

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 https://www.phpflow.com on September 4, 2021.

--

--

Parvez Alam

Hey, I am Parvez Alam. A software developer since 2009. I love learning and sharing knowledge. https://www.phpflow.com/