PHPackages                             ngekoding/codeigniter-datatables - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ngekoding/codeigniter-datatables

ActiveLibrary

ngekoding/codeigniter-datatables
================================

DataTables server-side for CodeIgniter

v1.0.11(2mo ago)373.9k↓36.4%20MITPHPPHP &gt;=5.6

Since Apr 28Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/ngekoding/codeigniter-datatables)[ Packagist](https://packagist.org/packages/ngekoding/codeigniter-datatables)[ RSS](/packages/ngekoding-codeigniter-datatables/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (13)Used By (0)

CodeIgniter DataTables
======================

[](#codeigniter-datatables)

DataTables server-side for CodeIgniter, supported for both CodeIgniter 3 and CodeIgniter 4.

**Note:** This library only handle the server-side part, you will still need to set up the client-side components, such as jQuery, the DataTables library, and the necessary styles. **Don't worry, we've included examples below to help you get started.**

Requirements
------------

[](#requirements)

No additional requirements are needed if you are already using CodeIgniter. Simply integrate this library into your existing project.

Installation
------------

[](#installation)

To install the library, use Composer. This command will handle the installation process for you:

```
composer require ngekoding/codeigniter-datatables
```

Usage
-----

[](#usage)

Below is a basic example of how to use this library. Feel free to customize the client-side configuration, such as defining searchable columns, orderable columns, and other DataTables options.

The usage of this library is similar for both CodeIgniter 3 and CodeIgniter 4. **The primary difference is in how you create the query builder.** Below are examples for both versions.

### CodeIgniter 3 Example

[](#codeigniter-3-example)

```
// CodeIgniter 3 Example

// Here we will select all fields from posts table
// and make a join with categories table
// IMPORTANT! We don't need to call ->get() here
$queryBuilder = $this->db->select('p.*, c.name category')
                    ->from('posts p')
                    ->join('categories c', 'c.id=p.category_id');

// The library will automatically detect the CodeIgniter version you are using
$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder);
$datatables->generate(); // done
```

### CodeIgniter 4 Example

[](#codeigniter-4-example)

```
// CodeIgniter 4 Example

$db = db_connect();
$queryBuilder = $db->from('posts p')
                   ->select('p.*, c.name category')
                   ->join('categories c', 'c.id=p.category_id');

// The library will automatically detect the CodeIgniter version you are using
$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder);
$datatables->generate(); // done
```

**The above examples will give you for [ajax data source (arrays)](https://datatables.net/examples/ajax/simple.html), so you need to make sure the table header you makes for the client side is match with the ajax response. We will talk about the objects data source below.**

### Client Side Examples

[](#client-side-examples)

You must include the jQuery and DataTables library.

```

    ID
    Title
    Category
    Description

$('#table-post').DataTable({
  processing: true,
  serverSide: true,
  ajax: {
    url: 'http://localhost/project/index.php/post/ajax_datatables', // Change with your own
    method: 'GET', // You are freely to use POST or GET
  }
})

```

Objects Data Source
-------------------

[](#objects-data-source)

As was mentioned above, the default data source we get is an arrays. It is easy also to get the objects data source.

To get objects response, you just need to call `asObject()` method.

```
$datatables->asObject()
           ->generate();
```

And then you can configure the client side with columns option to fit your data.

```
$('#table-post').DataTable({
  processing: true,
  serverSide: true,
  ajax: {
    url: 'http://localhost/project/index.php/post/ajax_datatables',
    method: 'GET',
  },
  columns: [
    { data: 'id' },
    { data: 'title' },
    { data: 'category' },
    { data: 'description' }
  ]
})

```

Some Others Settings
--------------------

[](#some-others-settings)

Some basic functionalities already available, here is the full settings you can doing to this library.

### Use class for spesify the CodeIgniter version

[](#use-class-for-spesify-the-codeigniter-version)

```
// General, use the second param to define the version (3 or 4)
$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder, 3);

// CodeIgniter 3
$datatables = new Ngekoding\CodeIgniterDataTables\DataTablesCodeIgniter3($queryBuilder);

// CodeIgniter 4
$datatables = new Ngekoding\CodeIgniterDataTables\DataTablesCodeIgniter4($queryBuilder);
```

### Available Options

[](#available-options)

```
$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder);

// Return the output as objects instead of arrays
$datatables->asObject();

// Only return title & category (accept string or array)
$datatables->only(['title', 'category']);

// Return all except the id
// You may use one of only or except
$datatables->except(['id']);

// Format the output
$datatables->format('title', function($value, $row) {
  return ''.$value.'';
});

// Add extra column
$datatables->addColumn('action', function($row) {
  return 'Delete';
});

// Add column alias
// It is very useful when we use SELECT JOIN to prevent column ambiguous
$datatables->addColumnAlias('p.id', 'id');

// Add column aliases
// Same as the addColumnAlias, but for multiple alias at once
$datatables->addColumnAliases([
  'p.id' => 'id',
  'c.name' => 'category'
]);

// Add squence number
// The default key is `sequenceNumber`
// You can change it with give the param
$datatables->addSequenceNumber();
$datatables->addSequenceNumber('rowNumber'); // It will be rowNumber

// Add order escape for a specific column
// Useful when ordering by raw expressions or aggregate functions like COUNT()
// This will skip identifier protection for the given column
$datatables->addOrderEscape('name', FALSE);

// Add order escapes for multiple columns at once
// Each key is the column name, and the value is the escape flag (TRUE/FALSE)
$datatables->addOrderEscapes([
  'name' => FALSE,
  'category' => FALSE
]);

// Don't forget to call generate to get the results
$datatables->generate();

// Optional usage: get the response data as an array instead of sending JSON
$data = $datatables->generate(true);
```

Complete Example
----------------

[](#complete-example)

I already use this library to the existing project with completed CRUD operations, you can found it [here](https://github.com/ngekoding/ci-crud).

Please look at these files:- application/composer.json
- application/controllers/Post.php
- application/models/M\_post.php
- application/views/template.php
- application/views/posts/index-datatables.php
- application/views/posts/index-datatables-array.php
- application/helpers/api\_helper.php
- assets/js/custom.js

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance86

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~128 days

Recently: every ~140 days

Total

12

Last Release

70d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/badefbaef2fd421d3b05261b2eb984562dee50392d83632bdb6549aff655e25e?d=identicon)[ngekoding](/maintainers/ngekoding)

---

Top Contributors

[![ngekoding](https://avatars.githubusercontent.com/u/11625690?v=4)](https://github.com/ngekoding "ngekoding (19 commits)")

---

Tags

codeignitercodeigniter-datatablesdatatablesdatatables-serversidephp

### Embed Badge

![Health badge](/badges/ngekoding-codeigniter-datatables/health.svg)

```
[![Health](https://phpackages.com/badges/ngekoding-codeigniter-datatables/health.svg)](https://phpackages.com/packages/ngekoding-codeigniter-datatables)
```

###  Alternatives

[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k172.9M1.8k](/packages/symfony-security-bundle)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[laravel/reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.

1.6k9.4M48](/packages/laravel-reverb)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k5](/packages/elgg-elgg)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
