Server Side Processing DataTable with PHP and MySQL

Server Side Processing DataTable with PHP and MySQL

Server Side Processing DataTable with PHP and MySQL

DataTables is a jQuery library used to show the entire list of records in an HTML table. It combines some features like key search, pagination list, data sorting, filter and etc. In DataTables we can limit the number of records to be presented per page.

DataTables gives both client-side and server-side processing. In this post, we are going to utilize the database results by using DataTables server-side processing. A PHP file used to calls requested columns and returns array of results. This resultant array is encoded to the JSON format which will send the response to the DataTables AJAX script.

DataTable Defining Code

The following code uses to define HTML code for the DataTable. This code has needed CSS and JavaScript library includes a top of the page. The table HTML tag has an id attribute which is used to define and set the table as a DataTable.




and HTML Table details

S.No. Post Name Description

DataTable Initialize using jQuery script

The following code shows the jQuery DataTable Initialize by setting the needed DataTable property key features. In this code, the serverSide property is set as true and the server side file path is specified for the ajax property key. These keys are used to set the server side processing for the DataTable.

$('#post_list').dataTable({
	"bProcessing": true,
 	"serverSide": true,
 	"ajax":{
        url :"post_list.php",
        type: "POST",
        error: function(){
          $("#post_list_processing").css("display","none");
        }
  	}
});

Server-Side Processing script

The following PHP code is provided the data set details as JSON format. Here the data will get from MySql table with help of SELECT with ORDER and LIMIT keys. It contains column name and respective values as an array.

What's Your Reaction?

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0