PHPackages                             livecms/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. livecms/datatables

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

livecms/datatables
==================

Live CMS Datatables

v0.1.1(7y ago)11331MITPHPPHP &gt;=7.0

Since Sep 3Pushed 7y ago1 watchersCompare

[ Source](https://github.com/livecms/datatables)[ Packagist](https://packagist.org/packages/livecms/datatables)[ Docs](https://github.com/mrofi/livecms-datatables)[ RSS](/packages/livecms-datatables/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Welcome to LiveCMS DataTables For Laravel 5.5 or above
======================================================

[](#welcome-to-livecms-datatables-for-laravel-55-or-above)

What is ?
---------

[](#what-is-)

This package can deal with Javascript DataTables.

Features
--------

[](#features)

- Full Yajra DataTables features with some improvements. See [documentation](https://yajrabox.com/docs/laravel-datatables/master)

### Notes

[](#notes)

- Please add DataTables js and css, see [DataTables Documentation](https://datatables.net/)

How to use?
-----------

[](#how-to-use)

### Install via composer

[](#install-via-composer)

```
composer require livecms/datatables
```

### Publish config file :

[](#publish-config-file-)

```
php artisan vendor:publish --provider="LiveCMS\DataTables\DataTablesServiceProvider"
```

Edit 'datatables.php' config file.

### DataTables Class

[](#datatables-class)

Definition : `DataTables(LiveCMS\DataTables\HasDataTables $object, $url, array $fields = null)`

### Define Base Query

[](#define-base-query)

You can create a new class or use existing one. What you need to do is implement interface `LiveCMS\DataTables\HasDataTables` and create a method : `toDataTablesQuery()`This method must return a Laravel Query Builder, Relation, Collection or API Resource Collection

```
use App\Http\Resources\SportResource;
use App\Sport;
use LiveCMS\DataTables\HasDataTables;

class SportDataTables implements HasDataTables
{
    public function toDataTablesQuery()
    {
        // use one of these types
        return app(Sport::class)->newQuery(); // Builder
        return app(Sport::class)->players(); // Relation
        return Sport::get(); // Collection
        return SportResource::collection(Sport::get()); // API Resource Collection
    }
}
```

### Define Fields

[](#define-fields)

Fields defined by array. Example : You have fields : `id, name, is_active, action` which are `id, name and is_active` is in your model data and `action` field is a custom field that contains action buttons : `Edit and Delete` button

Then your fields would be like this and the explanation is in the bellow :

```
$fields = [
    'ID',
    'Sport Name' => 'name',
    'Is Active' => [
        'display' => function ($isActive) {
            return new \Illuminate\Support\HtmlString(
                $isActive ? 'True' : 'False';
            );
        }
    ],
    'Action' => function ($row) {
        return new \Illuminate\Support\HtmlString(
            'EditDelete';
        );
    }
];
```

You can place fields in method : `getDataTablesFields()` in class that implement `HasDataTables` interface, i.e.

```
use Illuminate\Support\HtmlString;
use LiveCMS\DataTables\HasDataTables;

class SportDataTables implements HasDataTables
{
    ....

    public function getDataTablesFields()
    {
        return [
            'ID',
            'Sport Name' => 'name',
            'Is Active' => [
                'display' => function ($isActive) {
                    return new HtmlString(
                        $isActive ? 'True' : 'False';
                    );
                }
            ],
            'Action' => function ($row) {
                return new HtmlString(
                    'EditDelete';
                );
            }
        ];
    }
}
```

or in third parameter when you call DataTables class. See [definition](#datatables-class)

### Field Definition Explaination :

[](#field-definition-explaination-)

Every single field in the array automatically will be converted into this default form :

1. Field exists in database

```
    'Label' => [
        'name' => 'label', // field name or will use lower case of label if not defined
        'data' => 'label', // data name or will use lower case of label if not defined
        'orderable' => true, // if this field is not orderable, set false,
        'searchable' => true, // if this field is not searchable, set false
        'display' => function ($value) {
            return new \Illuminate\Support\HtmlString('value');
        ,
        // if you want to mark up the value, use display.

    ],
```

2. Field doesn't exist in database or custom field

```
    'Label' => function ($row) {
        return 'anything';
    },
```

**Notes : Don't forget use class `\Illuminate\Support\HtmlString` to un-escape the html code**

### Let's play

[](#lets-play)

Controller :

```
use LiveCMS\DataTables\DataTables;

class SportController extends Controller
{
    protected $dataTables;

    public function __construct(SportDataTables $sportDataTables)
    {
        $dataTablesUrl = url('/admin/sport/data'); // route('routename')
        $this->dataTables = new DataTables($sportDataTables, $dataTablesUrl);
    }

    public function getIndex()
    {
        $this->dataTables->renderView();
        return view('admin.sports.index');
    }

    public function postData(Request $request)
    {
        return $this->dataTables->renderData();
    }

}
```

View : `file : admin/sports/index.blade.php`

```

                @foreach ($dataTablesCaptions as $field)
                {{ $field }}
                @endforeach

        $(document).ready(function() {
            $('#datatables').DataTable({!! $dataTablesView !!});
        });

```

LICENSE
-------

[](#license)

MIT

CONTRIBUTING
------------

[](#contributing)

Fork this repo and make a pull request

ISSUE AND DISCUSSION
--------------------

[](#issue-and-discussion)

Please create new issue or see the closed issues too.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

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

Every ~1 days

Total

2

Last Release

2809d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7432391?v=4)[Mokhamad Rofiudin](/maintainers/mrofi)[@mrofi](https://github.com/mrofi)

---

Top Contributors

[![mrofi](https://avatars.githubusercontent.com/u/7432391?v=4)](https://github.com/mrofi "mrofi (16 commits)")

### Embed Badge

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

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

###  Alternatives

[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.5M178](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

8314.0M314](/packages/illuminate-redis)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)

PHPackages © 2026

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