I will show you how we can use DataTable API 1.10 in Codeigniter framework. You may also be interested in DataTable CRUD Example using Codeigniter, MySQL and AJAX

Grid view in an Web page is a very important now-a-days. Functions like sorting, searching, pagination is not an easy job in HTML tables. One of many grid view frameworks, an open source, light weight, highly flexible and customizable DataTable API is the most popular among. It offers features like AutoFill, inline editing, sticky header, responsive, and supports bootstrap. In version 1.10 DataTable has changed and improved over other versions.
In basic initialization datatable provides pagination, sorting, instant searching by loading whole data records at once. It can be a performance issue fetching large amount of data from server side. It will be better if we integrate server side pagination, searching and sorting, so we can break large amount data in chunk to increase the performance  significantly.

Prerequisites

Knowledge of PHP & Codeigniter, jQuery and AJAX
MySQL 5.x
Apache HTTP server 2.2
Codeigniter 2.1.4
Netbeans 7.x

You need to create assets folder in parallel to application folder for putting all asset files such as js, css, images etc.

Final Output

Codeigniter DataTable

Step 1. First thing is we need to create database table

Insert some data into the table

Step 2. Once you have codeigniter framework setup in place then configure database settings at location application/config/database.php

Step 3. Create a assets helper file under /application/helpers/assets_helper.php which gives us the URL for different assets like css, js etc.

Step 4. Modify the autoload.php file at location application/config/autoload.php as follows

Step 5. Create a model under application/models/cdmodel.php which will give us the data for the grid view. The below model file is pretty simple.

Step 6. Now create one controller called CdController under application/controller/cdcontroller.php with below code

Step 7. Now modify the application/config/routes.php file as follows

Step 8. Next create a view with the following code under /application/views/cds.php

Step 9. Download the assets directory and put it under project root directory

assets

Step 10. Run the application.

That’s all. Thanks for reading.

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

20 Thoughts on “DataTable using Codeigniter, MySQL and AJAX”

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.