Server side DataTable in PHP,MySQL and Ajax | DataTable in PHP and MySQL | DataTables Example - Server-side Processing with PHP | DataTables example - Server-side processing | Add column in DataTable in PHP

Server side DataTable Example

Server side DataTable Example

We often display data in tables. We do pagination, searching and sorting manually on those tables. DataTables is the beautiful concept for doing all these things you can say your food is ready to eat. You just need to use some peace of code and you can display data in tables with beautiful features like Pagination, Searching and Sorting.

We will display data in chunks so that this will be easy for MySQL to serve the data. It'll also increase your performance You can change your pagination limit as well for example if you wanted to display 25 records on every page you can do that very easily.


Here is you HTML code:

Here in this HTML code I have included DataTable CSS and DataTable JQuery later on I have called DataTable function with passing the parameter processing and serverSide as true. Then I called an Ajax request to pull the data from back end.

Then I'm defining the columns which I wanted to display and which I have added in table header.

We also can disable the sorting functionality on any column by keeping the orderable parameter false. You can use it according to your need I just have given example of email column which I don't wanted sortable.

I have used columnDefs for adding a new column and I also kept orderable false here because It was an action column and I'll use some buttons here like edit and delete and these buttons don't need to be sorted. Inside columnDefs 'targets' is the column index.



Here is the server side code which is serving the data to the front end.

response.php

I have a table called 'users' inside 'datatables' database. I wanted to display name,email and phone fields.

Here is the database connection code.

connection.php

Share This:

3 thoughts on “Server side DataTable in PHP,MySQL and Ajax | DataTable in PHP and MySQL | DataTables Example - Server-side Processing with PHP | DataTables example - Server-side processing | Add column in DataTable in PHP

Leave a Reply

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