PHPackages                             camohub/laravel-datagrid - 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. camohub/laravel-datagrid

ActiveLibrary

camohub/laravel-datagrid
========================

Datagrid for Laravel

1.3.13(4y ago)083mitPHPPHP &gt;=7.0.0

Since Jul 23Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (64)Used By (0)

camohub/laravel-datagrid
========================

[](#camohublaravel-datagrid)

Laravel datagrid
----------------

[](#laravel-datagrid)

This is the datagrid for Laravel models.

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

[](#installation)

```
composer install camohub/laravel-datagrid

```

Description
-----------

[](#description)

Datagrid constructor accepts instance of Illuminate\\Database\\Eloquent\\Builder or Illuminate\\Database\\Query\\Builder as datasource.

This package is based on form GET request. Whole table is a form. You can simply catch submit event if you need. Empty inputs are disabled on submit by js and automatically removed from url. Datagrid contains this groups of inputs:

- **sort inputs** - every sortalbe field has its own hidden input. After click on the sortable column js sets the hidden input value. If value is empty hidden input is disabled.
- **filter inputs** - filter inputs triggers form submit on input event. There is also timeout as throttling to wait for another input events. This timeout can be set in php grid definition globally by setJSFilterTimeout().
- **perPage select** - onchange event triggers form submit immediately.
- **page** - paginator page param is also as hidden input.

This form submit implementation has one little disadvantage. It removes all other GET parameters from url. But it is easy to fix it. You can set all necessary GET parameters via $grid-&gt;addGetParam('name').

Example
-------

[](#example)

Controller code could implement a method which returns datagrid instance.

```
public function getArticlesDatagrid()
{
    $grid = new Datagrid(Article::with('user'));

    $grid->addColumn('id')
        ->setSort();

    $grid->addColumn('title')
        ->setSort()
        ->setFilter(function($model, $value) {
            return $value ? $model->where('title', 'like', "%$value%") : $model;
        });

    $grid->addColumn('created_at', 'Created')
        // Needs valid js regexp pattern.
        ->setJSFilterPattern('\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}')
        ->setRender(function($value, $item) {
            return '' . $value->format('d.m.Y H:i') . '';
        })
        // Turns off template html escaping.
        ->setNoEscape()
        ->setSort();

    $grid->addColumn('visible', 'Visible')
        ->setOutherClass(function($value, $row) {
            return $value ? 'bg-primary text-center' : 'bg-danger text-center';
        })
        ->setSelectFilter([0 => 'hidden', 1 => 'active'], 'all')
        ->setFilter(function ($model, $value) {
            return $model->where('visible', $value);
        });

    // HasOne relation
    $grid->addColumn('user.name', 'User');

    // ManyHasMany relation
    $grid->addColumn('user.roles', 'Roles')
        ->setRender(function($value, $item) {
            return $value->map( function($value) { return $value->name; } )->join(', ');
        });

    // TYPE_CUSTOM intended for content not related to model.
    $grid->addColumn('', '', Column::TYPE_CUSTOM)
        ->setNoEscape()
        ->setRender(function($value, $item) {
            return '
                edit
                visibility
                delete
            ';
        });

    return $grid;
}
```

And the template could look like

```
{{$grid->render()}}
```

Options
-------

[](#options)

There are two groups of options. Global datagrid options and column specific options.

### Datagrid options

[](#datagrid-options)

- **setDefaultSort()** - sort callback used when no other sort filter is in use.
- **setDefaultPerPage()** - yes it really sets the default perPage items number.
- **setPerPage()** - expects array with possible dropdown options like \[10, 25, 50, 100\].
- **setOnEachSide()** - it is the wrapper above the Laravel pagination onEachSide() option.
- **setTableClass()** - default is 'table table-striped table-hover table-bordered';
- **setJSFilterTimeout()** - sets javascript timeout on input event. Default is 250ms.
- **setSubmitOnEnter()** - prevent submit on input event and will wait for hit enter key to submit. This option is possible to set for the whole grid or for one column. Does not affect sorting, pagination and perPage select. They are still automatically submited.
- **setGetParams()** - form submit removes all GET params from url which are not the part of the form. Request will contain only form inputs as GET prameters. setGetParams('paramName') will include all necessary GET params which should be included in all datagrid GET requests.

### Column options

[](#column-options)

- **setRender()** - accepts callback with two parameters - value and row.
- **setSort()** - accepts empty to simple sort according flied name or callback which gets two params - queryBuilder and sort value.
- **setFilter()** - accepts callback with two parameters - queryBuilder and filter value. Filter callback is not called if filter value is NULL or empty string. Other values like 0 will call the filter.
- **setFilterSelect()** - expects associative array and options prompt parameter. This function renders select element in the filter field.
- **setJSFilterPattern()** - accepts js regexp patterns as string. If value does not match the pattern validator will block the request and will add .text-danger class to input field.
- **setSubmitOnEnter()** - prevent submit on input event and will wait for hit enter key to submit. This option is possible to set for the whole grid or for one column. Does not affect sorting, pagination and perPage select. They are still automatically submited.
- **setFilterRender()** - allows you to render filter input manually. Be sure rendered filter input has css class chgrid-filter.
- **setNoEscape()** - custom render wont be escaped. Template use {!! !!} instead of {{}}.
- **setOutherClass()** - accepts callback. Callback will be useful if you need to make some conditional styles for the field. Callback will get two parameters - value and row.
- **setOutherTitleClass** - accepts string value. Will set up css class of TH element with title.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

63

Last Release

1721d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ad9433afd982997b82d270954a1999c37ac2b20e049928f7594b9977903bde7?d=identicon)[camohub](/maintainers/camohub)

---

Top Contributors

[![camohub](https://avatars.githubusercontent.com/u/8393426?v=4)](https://github.com/camohub "camohub (79 commits)")

### Embed Badge

![Health badge](/badges/camohub-laravel-datagrid/health.svg)

```
[![Health](https://phpackages.com/badges/camohub-laravel-datagrid/health.svg)](https://phpackages.com/packages/camohub-laravel-datagrid)
```

PHPackages © 2026

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