PHPackages                             rundiz/data-table - 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. [Database &amp; ORM](/categories/database)
4. /
5. rundiz/data-table

ActiveLibrary[Database &amp; ORM](/categories/database)

rundiz/data-table
=================

The data table class for listing data in the table.

v0.1(9y ago)1201MITPHPPHP &gt;=5.4.0

Since Oct 31Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/Rundiz/data-table)[ Packagist](https://packagist.org/packages/rundiz/data-table)[ RSS](/packages/rundiz-data-table/feed)WikiDiscussions master Synced 2mo ago

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

Data Table
==========

[](#data-table)

Data table class for generate table with header, footer, data list, bulk actions, pagination. This repository use the idea of WordPress's list table class to generate data table easily and supported responsive table.

[![Latest Stable Version](https://camo.githubusercontent.com/6553cd0a40a4a1f34f57eed7fe5aa192699792012213033d9e649c434950352e/68747470733a2f2f706f7365722e707567782e6f72672f72756e64697a2f646174612d7461626c652f762f737461626c65)](https://packagist.org/packages/rundiz/data-table)[![License](https://camo.githubusercontent.com/41bd9c992c99d0b4b71f13b7360f507e9a1c7001d5a8584c0a06ebfad30e09f2/68747470733a2f2f706f7365722e707567782e6f72672f72756e64697a2f646174612d7461626c652f6c6963656e7365)](https://packagist.org/packages/rundiz/data-table)[![Total Downloads](https://camo.githubusercontent.com/e43a1d2065ed0a3c7073f4b8ecedc3ecef017a9222a3d317fc80a727d994f8cd/68747470733a2f2f706f7365722e707567782e6f72672f72756e64697a2f646174612d7461626c652f646f776e6c6f616473)](https://packagist.org/packages/rundiz/data-table)

Tested up to PHP 8.5.

Example
-------

[](#example)

### Install

[](#install)

I recommend you to install this library via Composer and use Composer autoload for easily include the files. If you are not using Composer, you have to manually include these files by yourself.
Please make sure that the path to files are correct.

```
require_once '/path/to/Rundiz/DataTable/DataTable.php';
require_once '/path/to/Rundiz/DataTable/Database.php';
if (!class_exists('\\Rundiz\\Pagination\\Pagination')) {
    require_once '/path/to/Pagination.php';
}
```

Import test-data.sql to MySQL or MariaDB (for test only).

### Configuration

[](#configuration)

You have to provide db configuration to the class to read, update, delete the data.

```
$db['dsn'] = 'mysql:dbname=YOUR_DB_NAME;host=localhost;port=3306;charset=UTF8';
$db['username'] = 'admin';
$db['password'] = 'pass';
$db['options'] = [
    \PDO::ATTR_EMULATE_PREPARES => true,
    \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION // throws PDOException.
];
$db['tablename'] = 'people_dummy_data';
```

### Override

[](#override)

You have to override the Rundiz\\DataTable\\DataTable by extends to sub class. Open the parent class or the \[API document\] () to see more about methods and properties that are able to override.
Assume that the sub class file name is PeopleDummyDataTable.php.

```
class PeopleDummyDataTable extends \Rundiz\DataTable\DataTable
{

    /**
     * @var string My table name.
     */
    public $myTable;

    /**
     * {@inheritDoc}
     */
    protected function columnDefault($row, $column_unique_name)
    {
        switch ($column_unique_name) {
            default:
                if (isset($row->{$column_unique_name})) {
                    return $row->{$column_unique_name};
                }
        }
    }// columnDefault

    /**
     * Special column method for "name".
     *
     * @param object $row Data from PDO in each row from fetchAll() method.
     * @return string Return column content. Use return, not echo.
     */
    protected function columnName($row)
    {
        return $row->first_name . ' ' . $row->last_name;
    }// columnName

    /**
     * {@inheritDoc}
     */
    protected function getColumns()
    {
        return [
            'name' => 'Full name',
            'email' => 'Email',
            'gender' => 'Gender',
            'ip_address' => 'IP Address',
        ];
    }// getColumns

    /**
     * {@inheritDoc}
     */
    public function prepareData()
    {
        if (!class_exists('\\Rundiz\\Pagination\\Pagination') || !is_object($this->Pagination)) {
            throw new \Exception('The class \\Rundiz\\Pagination\\Pagination is not exists, please install rundiz/pagination class.');
        }

        $current_page = $this->getCurrentPage();

        $sql = 'SELECT COUNT(*) FROM `' . $this->myTable . '`';
        $stmt = $this->Database->PDO->prepare($sql);
        $stmt->execute();
        $total_items = $stmt->fetchColumn();
        unset($stmt);

        // order (column) and sort (asc, desc)
        $order = 'id';
        if (isset($_GET[$this->orderQueryName])) {
            if (in_array($_GET[$this->orderQueryName], ['id', 'first_name', 'last_name', 'email', 'gender', 'ip_address'])) {
                $order = $_GET[$this->orderQueryName];
            }
        }
        $sort = 'ASC';
        if (isset($_GET[$this->sortQueryName])) {
            if (in_array(strtoupper($_GET[$this->sortQueryName]), ['ASC', 'DESC'])) {
                $sort = strtoupper($_GET[$this->sortQueryName]);
            }
        }

        $sql = str_replace('COUNT(*)', '*', $sql);
        $sql .= ' ORDER BY `' . $order . '` ' . $sort;
        $sql .= ' LIMIT ' . (($current_page - 1) * $this->itemsPerPage) . ', ' . $this->itemsPerPage;
        $stmt = $this->Database->PDO->prepare($sql);
        $stmt->execute();
        $items = $stmt->fetchAll();
        unset($order, $sort, $sql, $stmt);

        $this->Pagination->base_url = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $this->paginationQueryName . '=%PAGENUMBER%';

        // set total items found and data items for listing to the properties.
        $this->totalItems = $total_items;
        $this->dataItems = $items;
        unset($current_page, $items, $total_items);
    }// prepareData

}
```

### Initialize the class

[](#initialize-the-class)

In the php file that will be display the data table, write this simple code.

```
include 'PeopleDummyDataTable.php';

$PDDTable = new PeopleDummyDataTable(['pdoconfig' => $db]);
$PDDTable->myTable = $db['tablename'];
$PDDTable->prepareData();
$PDDTable->display();
```

The `$db` variable is in the configuration section. Set your database values there correctly and run.

### Styles and scripts

[](#styles-and-scripts)

The css and javascript is already in the **tests/via-http** folder. You can copy those files to use easily or customize to the way you want.

For more example, please look in tests folder.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance49

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

3483d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1568262?v=4)[vee w,](/maintainers/ve3)[@ve3](https://github.com/ve3)

---

Top Contributors

[![ve3](https://avatars.githubusercontent.com/u/1568262?v=4)](https://github.com/ve3 "ve3 (15 commits)")

---

Tags

bulk-actionsdata-tabledatabaselist-tablepaginationdatatabledata tablelist tabletable dataresponsive data tableresponsive list tablefolded table

### Embed Badge

![Health badge](/badges/rundiz-data-table/health.svg)

```
[![Health](https://phpackages.com/badges/rundiz-data-table/health.svg)](https://phpackages.com/packages/rundiz-data-table)
```

###  Alternatives

[omines/datatables-bundle

Symfony DataTables Bundle with native Doctrine ORM, Elastica and MongoDB support

2851.4M6](/packages/omines-datatables-bundle)[laravel-enso/tables

Data Table library with server-side processing and a VueJS component

63153.4k49](/packages/laravel-enso-tables)[livecontrol/eloquent-datatable

Eloquent DataTable plugin for server side ajax call handling.

59274.6k3](/packages/livecontrol-eloquent-datatable)[zfc-datagrid/zfc-datagrid

Laminas Module that provides a datagrid for different datasources and output formats

1223.2k](/packages/zfc-datagrid-zfc-datagrid)

PHPackages © 2026

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