DataTable using Codeigniter, MySQL and AJAX

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.


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


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

17 thoughts on “DataTable using Codeigniter, MySQL and AJAX

  1. Thai language is not work in filter function.
    In config.php
    ‘char_set’ => ‘utf8’,
    ‘dbcollat’ => ‘utf8_unicode_ci’,
    database and table and filed
    I set all to utf8
    It still not work. Please help

  2. Please guide me.

    related to your tutorial, please guide me.

    I’m saved some record against some users. i want to show these record to that specific user when they login and only search there record that store in db with there user id.

    Regards in-advance.

  3. Hello, I used your code and works perfect thank you, but I need to add a restriction of two dates to the query and I can’t find a way to make it work. Any help will be great. Thank you.

      1. Thank you Soumitra, I took the time to understand your code and with this I made mine work with all the necessary modifications. I didn’t use the link you shared just the original post of this page. Thanks again for the original post. Amazing work!

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.