PHPackages                             rougin/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rougin/datatables

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rougin/datatables
=================

Server-side of DataTables.net in PHP.

v0.1.0(1mo ago)44565MITPHPPHP &gt;=5.3.0CI passing

Since May 24Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/rougin/datatables)[ Packagist](https://packagist.org/packages/rougin/datatables)[ Docs](https://roug.in/datatables/)[ RSS](/packages/rougin-datatables/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Datatables
==========

[](#datatables)

[![Latest Version on Packagist](https://camo.githubusercontent.com/28223539762f79917ae30c9cd561c7d77b327620b7709aeec8a8be2a432c5171/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f7567696e2f646174617461626c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/datatables)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/rougin/datatables/blob/master/LICENSE.md)[![Build Status](https://camo.githubusercontent.com/54f2a7a3a4e64f796a5afde55beeb8983509e35db6ec8f8e4fda44ad5760d63c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f7567696e2f646174617461626c65732f6275696c642e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/rougin/datatables/actions)[![Coverage Status](https://camo.githubusercontent.com/fe5f72ee85d9696f61edbf80d34699a5edb990eb392e5b7a55e3230ec71ef7ce/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726f7567696e2f646174617461626c65733f7374796c653d666c61742d737175617265)](https://app.codecov.io/gh/rougin/datatables)[![Total Downloads](https://camo.githubusercontent.com/ba3712feea96b52a79d6698944420270d5d7ed226886cd7a60579d681153b36f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f7567696e2f646174617461626c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/datatables)

`Datatables` is a simple PHP package that handles the [server-side of DataTables](https://datatables.net/examples/data_sources/server_side.html). Its server-side response can be used from the HTML which requires little to no configuration.

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

[](#installation)

Install the `Datatables` package via [Composer](https://getcomposer.org/):

```
$ composer require rougin/datatables
```

Basic usage
-----------

[](#basic-usage)

Prior in configuring `Datatables`, kindly ensure that the `serverSide` property is set to `true` in the Javascript part:

```
// index.js

let options = { processing: true }

options.ajax = 'http://localhost:8000'

options.serverSide = true

new DataTable('#example', options)
```

```

```

Note

For more information in the above example, kindly see the [official guide](https://datatables.net/examples/data_sources/server_side.html) on how to implement server-side rendering of data to `DataTables`.

From the PHP part, use the `Table` class to define the specified table:

```
// index.php

use Rougin\Datatables\Request;
use Rougin\Datatables\Table;

// ...

// The $_GET variable should be returned ---
// and parsed as array ------
$request = new Request($_GET);
// -----------------------------------------

// Parse columns based on the Request ---------
$table = Table::fromRequest($request, 'users');
// --------------------------------------------
```

By default, getting columns from the payload of the Javascript part of `DataTables` does not provide its name (e.g., `forename`, `surname`, etc.). As the column name is required for getting its data from a source, there is a need to map its column to the database table:

```
// index.php

// ...

// The first column will be named as "forename" ---
$table->mapColumn(0, 'forename');
// ------------------------------------------------

$table->mapColumn(1, 'surname');
$table->mapColumn(2, 'position');
$table->mapColumn(3, 'office');
$table->mapColumn(4, 'date_start');
$table->mapColumn(5, 'salary');

// ...
```

Once the table has been properly configured, initialize a source (e.g., `PdoSource`) that will be used for getting the data of the specified table:

```
// index.php

use Rougin\Datatables\Source\PdoSource;

// ...

// Create a PDO instance... --------------
$dsn = 'mysql:host=localhost;dbname=demo';

$pdo = new PDO($dsn, 'root', /** ... */);
// ---------------------------------------

// ...then pass it to the PdoSource ---
$source = new PdoSource($pdo);
// ------------------------------------

// ...
```

Then use the `Query` class to generate the requested data:

```
// index.php

use Rougin\Datatables\Query;

// ...

/** @var \Rougin\Datatables\Source\SourceInterface */
$source = /** ... */;

$query = new Query($request, $source);

/** @var \Rougin\Datatables\Result */
$result = $query->getResult($table);
```

The `getResult` from the `Query` class returns a `Result` class in which returns the response as an array or as JSON format:

```
// index.php

// ...

/** @var \Rougin\Datatables\Result */
$result = $query->getResult($table);

echo $result->toJson();
```

```
$ php index.php
```

```
{
  "draw": 1,
  "recordsFiltered": 57,
  "recordsTotal": 57,
  "data":
  [
    [
      "Airi",
      "Satou",
      "Accountant",
      "Tokyo",
      "2008-11-28",
      "162700.0"
    ],
    [
      "Angelica",
      "Ramos",
      "Chief Executive Officer (CEO)",
      "London",
      "2009-10-09",
      "1200000.0"
    ],

    // ...
  ]
}
```

Column formatters
-----------------

[](#column-formatters)

Each table column accepts an optional formatter callback to transform values before output, matching the [SSP formatter contract](https://datatables.net/examples/data_sources/server_side.html):

```
// index.php

// ...

// Get the columns from the table ---
$columns = $table->getColumns();
// ----------------------------------

// Format salary as currency --------------
$columns[5]->setFormatter(function ($value)
{
    return '$' . number_format($value, 2);
});
// ----------------------------------------

// Compose full name from two fields -----
$fn = function ($value, $row)
{
    return $value . ' ' . $row['surname'];
};

$columns[0]->setFormatter($fn);
// ---------------------------------------

// ...
```

Creating custom sources
-----------------------

[](#creating-custom-sources)

To create a custom source, kindly use the `SourceInterface` for its implementation:

```
namespace Rougin\Datatables\Source;

use Rougin\Datatables\Request;
use Rougin\Datatables\Table;

interface SourceInterface
{
    /**
     * Returns the total items after filter. If no filters
     * are defined, the value should be same with getTotal.
     *
     * @return integer
     */
    public function getFiltered();

    /**
     * Returns the items from the source.
     *
     * @return string[][]
     */
    public function getItems();

    /**
     * Returns the total items from the source.
     *
     * @return integer
     */
    public function getTotal();

    /**
     * Sets the payload to be used in the source.
     *
     * @param \Rougin\Datatables\Request $request
     *
     * @return self
     */
    public function setRequest(Request $request);

    /**
     * Sets the table to be used in the source.
     *
     * @param \Rougin\Datatables\Table $table
     *
     * @return self
     */
    public function setTable(Table $table);
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/rougin/datatables/blob/master/CHANGELOG.md) for more recent changes.

Contributing
------------

[](#contributing)

See [CONTRIBUTING](https://github.com/rougin/datatables/blob/master/CONTRIBUTING.md) on how to contribute.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](https://github.com/rougin/datatables/blob/master/LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance92

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

38d ago

### Community

Maintainers

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

---

Top Contributors

[![rougin](https://avatars.githubusercontent.com/u/6078637?v=4)](https://github.com/rougin "rougin (87 commits)")

---

Tags

datatablephp-tablephp-datatables

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[bllim/datatables

Server-side handler of DataTables Jquery Plugin for Laravel 4

263418.7k4](/packages/bllim-datatables)[laravel-enso/tables

Server-side data tables and export backend for Laravel Enso

63355.1k83](/packages/laravel-enso-tables)[nullref/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

7292.8k](/packages/nullref-yii2-datatables)[tigrang/cakephp-datatable

CakePHP DataTable Plugin

465.2k](/packages/tigrang-cakephp-datatable)[webinarium/datatables-bundle

DataTables Symfony bundle

1732.4k](/packages/webinarium-datatables-bundle)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.2k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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