PHPackages                             nlybe/datatables\_api - 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. nlybe/datatables\_api

ActiveElgg-plugin[Utility &amp; Helpers](/categories/utility)

nlybe/datatables\_api
=====================

DataTables integration on Elgg

5.14(3y ago)01652GPL-2.0PHP

Since Dec 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/nlybe/Elgg-DataTablesAPI)[ Packagist](https://packagist.org/packages/nlybe/datatables_api)[ Docs](https://github.com/nlybe/Elgg-DataTablesAPI)[ RSS](/packages/nlybe-datatables-api/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (12)Used By (2)

DataTables API for Elgg
=======================

[](#datatables-api-for-elgg)

[![Elgg 5.0](https://camo.githubusercontent.com/2cb7ed947ca59012a2c6c756378bff6a5e08195fbb4292e1b2973c2859c95f3c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c67672d352e302d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/2cb7ed947ca59012a2c6c756378bff6a5e08195fbb4292e1b2973c2859c95f3c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c67672d352e302d6f72616e67652e7376673f7374796c653d666c61742d737175617265)

[DataTables](https://datatables.net/) integration on Elgg. This plugin offers an API which can be used from other plugins on Elgg platforms in order to populate information in data tables.

[DataTables](https://datatables.net/) is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement and offers advanced interaction controls to any HTML table.

The plugin for Elgg offers the following options:

- Create a simple DataTable by loading all records (not suggested for large data set).
- Get records from database by using ajax requests.
- Use server-side options that DataTables provides, so all paging, searching and ordering actions are being made by using ajax requests to get the required data.
- Add export buttons such as copy, csv, pdf and print, if enabled in settings.

As a usage example you can see the [Elgg Entity Lists](https://github.com/nlybe/Elgg-Entity-Lists) which uses the datatables\_api plugin for generating lists of Elgg entities.

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

[](#installation)

Use composer to install this plugin. On site root folder, run the command:

```
composer require nlybe/datatables_api
```

How to Use
----------

[](#how-to-use)

### Example 1 - Use ajax request and Server-side processing

[](#example-1---use-ajax-request-and-server-side-processing)

```
$dt_options = [
    'action' => 'demoplugin/users',
];

$dt_options['headers'] = [
    ['name' => 'id', 'label' => elgg_echo('ID')],
    ['name' => 'name', 'label' => elgg_echo('Name')],
    ['name' => 'username', 'label' => elgg_echo('Username')],
    ['name' => 'email', 'label' => elgg_echo('Email')],
    ['name' => 'created', 'label' => elgg_echo('Created')],
    ['name' => 'updated', 'label' => elgg_echo('Updated')],
    ['name' => 'actions', 'label' => elgg_echo('Actions')],
];

echo elgg_view('datatables_api/dtapi_ajax', $dt_options);
```

On 'views/default/resources/demoplugin/users.php' use the following code:

```
$search = get_input('search');

$options = array(
    'type' => 'user',
    'limit' => 0,
    'count' => true,
);

$options["joins"] = [];
$options["wheres"] = [];
$dbprefix = elgg_get_config('dbprefix');
if ($search && !empty($search['value'])) {
    $query = $search['value'];

    array_push($options["joins"], "JOIN {$dbprefix}users_entity ge ON e.guid = ge.guid");
    array_push($options["wheres"], "(ge.name LIKE '%$query%' OR ge.username LIKE '%$query%' OR ge.email LIKE '%$query%')");
}

$totalEntries = elgg_get_entities_from_metadata($options);

$options['count'] = false;
$options['limit'] = max((int) get_input("length", elgg_get_config('default_limit')), 0);
$options['offset'] = get_input ("start", 0);
$entities = elgg_get_entities_from_metadata($options);

$dt_data = [];
if ($entities) {
    foreach ($entities as $e) {
        $dt_data_tmp = [];

        // datatable
        $dt_data_tmp['id'] = $e->getGUID();
        $dt_data_tmp['name'] = elgg_view('output/url', array(
            'href' => $e->getURL(),
            'text' => $e->name,
            'title' => elgg_echo('entity_lists:admin:elgg_objects:view_entity'),
            'is_trusted' => true,
        ));
        $dt_data_tmp['username'] = elgg_view('output/url', array(
            'href' => $e->getURL(),
            'text' => $e->username,
            'title' => elgg_echo('entity_lists:admin:elgg_objects:view_entity'),
            'is_trusted' => true,
        ));

        $dt_data_tmp['email'] = $e->email;
        $dt_data_tmp['created'] = date("r", $e->time_created);
        $dt_data_tmp['updated'] = date("r", $e->time_updated);
        $dt_data_tmp['actions'] = elgg_view('output/url', array(
            'href' => "action/entity/delete?guid={$e->getGUID()}",
            'text' => elgg_view_icon('remove'),
            'title' => elgg_echo('delete:this'),
            'is_action' => true,
            'data-confirm' => elgg_echo('deleteconfirm'),
        ));

        array_push($dt_data, $dt_data_tmp);
    }
}

$total_rows = count($entities);
$draw = get_input('draw');
$result = [
    'draw' => isset($draw)?intval($draw):1,
    'recordsTotal' => $totalEntries,
    'recordsFiltered' => $totalEntries,
    'data' => $dt_data,
];

// release variables
unset($entities);

echo json_encode($result);
exit;
```

### Example 2

[](#example-2)

The sample code below will display a DataTable with 3 columns. It's suggested for small about of records only.

```
// set an array with titles of table
$vars['dt_titles'] = array(
    elgg_echo('my_plugin:datatables:example:title1'),
    elgg_echo('my_plugin:datatables:example:title2'),
    elgg_echo('my_plugin:datatables:example:title3'),
);

// set an array with data of table
$dt_data = [];
$entities = elgg_get_entities($options);
foreach (entities as $e) {
    $dt_data_tmp = [];
    $dt_data_tmp['guid'] = $e->getGUID();
    $dt_data_tmp['title'] = $e->title;
    $dt_data_tmp['likes'] = calculate_likes($e);

    array_push($dt_data, $dt_data_tmp);
}
$vars['dt_data'] = $dt_data;

echo elgg_view('datatables_api/datatables_api', $vars);
```

Future Tasks List
-----------------

[](#future-tasks-list)

- Make a class for datatables, so all parameters will be passed by using methods of this class
- Integrate more options from [DataTables](https://datatables.net/examples/index/) like styling, search by column etc
- Fix ordering when use server-side options

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity70

Established project with proven stability

 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 ~237 days

Recently: every ~140 days

Total

11

Last Release

1121d ago

Major Versions

2.3.8 → 3.92018-12-15

3.10 → 4.112023-04-03

4.13 → 5.142023-06-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b3b4c3ed45bff26900a422f0271d660579bb6a309428222fabeedc2329b7979?d=identicon)[nlybe](/maintainers/nlybe)

---

Top Contributors

[![nlybe](https://avatars.githubusercontent.com/u/4714025?v=4)](https://github.com/nlybe "nlybe (34 commits)")

---

Tags

pluginelggdatatables

### Embed Badge

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

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

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.3k10](/packages/helsingborg-stad-municipio)

PHPackages © 2026

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