HTML table Listing, Searching and Sorting Using Codeigniter and Mysql – II

We have created html table listing using codeigniter and mysql database in previous codeigniter tutorial.We will add advanced feature in this table like any other table grid plugin.We will follow following steps to add pagination features.

I am using codeigniter pagination library for paging and url library for anchor tag.CI is providing many useful library classes that help to add beautiful features with in finger tips.

How to add Pagination in HTML table Listing

One of them is pagination class that use to set pagination parameters like no of records to show per page, next, prev icons, uri segment etc.We need to add pagination and url library into controller constructor method.

Modify index() controller method that will configure pagination parameters like below,

Modify getemployee() model method and passed limit parameters for pagination,

Now we will add pagination link on the bottom of table listing into home.php view file.

How to add sorting in HTML table listing Using codeigniter and MySQL

We have already added table listing with pagination, now we will add sorting on table column.I am creating single column sorting on table listing server side.

Step 1: We will change index() action method in home.php controller file.We will add two more parameters in uri for field_name and orderBy parameters.

Step 2: We need to modify employee_m.php model file and passed $sortfield and $orderBy parameters for sorting records.

Step 3: We will add anchor tab on table header column.I am using anchor() helper method to create anchor tag with in th tag.

We will refreshed table listing and found that th has been converted into anchor link, onclick of anchor th we will sort order of particular column field.

CodeIgniter listing with Searching

We will implement last phase of this tutorial.We will add searching functionality of table listing. Created a search input box that will take search string as a input and added a submit button for submit search string to controller method.I am using uri parameters for search string however you can pass using query string with pagination.

Step 1: We will create search input form which will have a submit button and input element in home.php view file.

Step 2: We will change index() action method in home.php controller file.We will add search term parameters in uri for search record in mysql table.

Step 3: We will modify employee_m.php model file get_employees() method and passed search term parameters for filter records.


This codeigniter tutorial help to create connection with MySQL database and fetch records to display into HTML table.We have added pagination using codeigniter pagination library an sorting records.I have also demonstrate to add search records into CI html table listing using URI.

You can download source code from below link.