PHPackages                             centeron/laravel-grids - 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. centeron/laravel-grids

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

centeron/laravel-grids
======================

Grids for Laravel 4 &amp; Laravel 5 frameworks

v1.4.1(5y ago)045MITPHPPHP &gt;=5.4.0

Since Aug 26Pushed 5y agoCompare

[ Source](https://github.com/centeron/laravel-grids)[ Packagist](https://packagist.org/packages/centeron/laravel-grids)[ Docs](https://github.com/centeron/laravel-grids)[ RSS](/packages/centeron-laravel-grids/feed)WikiDiscussions master Synced today

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

Grids
=====

[](#grids)

### `Data Grids Framework for Laravel`

[](#data-grids-framework-for-laravel)

Both Laravel 4 and Laravel 5 are supported.

Features
--------

[](#features)

- Data providers (php array, Eloquent model, Doctrine DBAL query object)
- Themes support
- Individual views for UI components
- Twitter Bootstrap v3 used by default
- Caching
- Smart input handling allows to avoid conflicts with get parameters &amp; easily place few interactive grids on same page
- Rich customization facilities
- Component architecture
- Declarative approach
- Constructing grids via strict object oriented API or configuration in php arrays
- Useful GridHelper helps to build tables fast
- Rich variety of components:
    - Excel and CSV export
    - *Records per page* dropdown
    - Show/hide columns UI control
    - Sorting
    - Filtering
    - Totals calculation (sum, average value, records count, etc)
    - Pagination
    - etc

Requirements
------------

[](#requirements)

- Laravel 4.X / 5.X
- laravelcollective/html package if you use Laravel5.X
- php 5.4+

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

[](#installation)

##### Step 1: Install package using [Composer](https://getcomposer.org)

[](#step-1-install-package-using-composer)

Add centeron/laravel-grids to "require" section of your composer.json

```
"require": {
    "centeron/laravel-grids": "^1.3.1"
},

```

For Laravel 5 you also need to add "laravelcollective/html":

```
"require": {
    "centeron/laravel-grids": "^1.3.1",
    "laravelcollective/html": "^5"
},

```

Then install dependencies using following command:

```
php composer install
```

Instead of editing composer.json and executing *composer install* you can just run following command:

For Laravel 4

```
php composer require centeron/laravel-grids
```

For Laravel 5

```
php composer require centeron/laravel-grids laravelcollective/html
```

##### Step 2: Laravel Setup

[](#step-2-laravel-setup)

Add following line to 'providers' section of app/config/app.php file:

```
'Centeron\Grids\ServiceProvider',
```

For Laravel 5 you also need to add "illuminate/html" service provider:

```
'Centeron\Grids\ServiceProvider',
'Collective\Html\HtmlServiceProvider',
```

You may also add facade aliases to your application configuration:

```
    'Form'  => 'Collective\Html\FormFacade',
    'HTML'  => 'Collective\Html\HtmlFacade',
    'Grids'     => 'Centeron\Grids\Grids',
```

Usage
-----

[](#usage)

##### Step 1. Instantiate &amp; Configure Grid

[](#step-1-instantiate--configure-grid)

See example below

```
# Let's take a Eloquent query as data provider
# Some params may be predefined, other can be controlled using grid components
$query = (new User)
    ->newQuery()
    ->with('posts')
    ->where('role', '=', User::ROLE_AUTHOR);

# Instantiate & Configure Grid
$grid = new Grid(
    (new GridConfig)
        # Grids name used as html id, caching key, filtering GET params prefix, etc
        # If not specified, unique value based on file name & line of code will be generated
        ->setName('my_report')
        # See all supported data providers in sources
        ->setDataProvider(new EloquentDataProvider($query))
        # Setup caching, value in minutes, turned off in debug mode
        ->setCachingTime(5)
        # Setup table columns
        ->setColumns([
            # simple results numbering, not related to table PK or any obtained data
            new IdFieldConfig,
            (new FieldConfig)
                ->setName('login')
                # will be displayed in table header
                ->setLabel('Login')
                # That's all what you need for filtering.
                # It will create controls, process input
                # and filter results (in case of EloquentDataProvider -- modify SQL query)
                ->addFilter(
                    (new FilterConfig)
                        ->setName('login')
                        ->setOperator(FilterConfig::OPERATOR_LIKE)
                )
                # optional,
                # use to prettify output in table cell
                # or print any data located not in results field matching column name
                ->setCallback(function ($val, ObjectDataRow $row) {
                    if ($val) {
                        $icon  = "&nbsp;";
                        $user = $row->getSrc();
                        return $icon . HTML::linkRoute('users.profile', $val, [$user->id]);
                    }
                })
                # sorting buttons will be added to header, DB query will be modified
                ->setSortable(true)
            ,
            (new FieldConfig)
                ->setName('status')
                ->setLabel('Status')
                ->addFilter(
                    (new SelectFilterConfig)
                        ->setOptions(User::getStatuses())
                )
            ,
            (new FieldConfig)
                ->setName('country')
                ->setLabel('Country')
                ->addFilter(
                    (new SelectFilterConfig)
                        ->setName('country')
                        ->setOptions(get_countries_list())
                )
            ,
            (new FieldConfig)
                ->setName('registration_date')
                ->setLabel('Registration date')
                ->setSortable(true)
            ,
            (new FieldConfig)
                ->setName('comments_count')
                ->setLabel('Comments')
                ->setSortable(true)
            ,
            (new FieldConfig)
                ->setName('posts_count')
                ->setLabel('Posts')
                ->setSortable(true)
            ,
        ])
        # Setup additional grid components
        ->setComponents([
            # Renders table header (table>thead)
            (new THead)
                # Setup inherited components
                ->setComponents([
                    # Add this if you have filters for automatic placing to this row
                    new FiltersRow,
                    # Row with additional controls
                    (new OneCellRow)
                        ->setComponents([
                            # Control for specifying quantity of records displayed on page
                            (new RecordsPerPage)
                                ->setVariants([
                                    50,
                                    100,
                                    1000
                                ])
                            ,
                            # Control to show/hide rows in table
                            (new ColumnsHider)
                                ->setHiddenByDefault([
                                    'activated_at',
                                    'updated_at',
                                    'registration_ip',
                                ])
                            ,
                            # Submit button for filters.
                            # Place it anywhere in the grid (grid is rendered inside form by default).
                            (new HtmlTag)
                                ->setTagName('button')
                                ->setAttributes([
                                    'type' => 'submit',
                                    # Some bootstrap classes
                                    'class' => 'btn btn-primary'
                                ])
                                ->setContent('Filter')
                        ])
                        # Components may have some placeholders for rendering children there.
                        ->setRenderSection(THead::SECTION_BEGIN)
                ])
            ,
            # Renders table footer (table>tfoot)
            (new TFoot)
                ->addComponent(
                    # TotalsRow component calculates totals on current page
                    # (max, min, sum, average value, etc)
                    # and renders results as table row.
                    # By default there is a sum.
                    new TotalsRow([
                        'comments',
                        'posts',
                    ])
                )
                ->addComponent(
                    # Renders row containing one cell
                    # with colspan attribute equal to the table columns count
                    (new OneCellRow)
                        # Pagination control
                        ->addComponent(new Pager)
                )
        ])
);
```

#### Step 2. Render Grid

[](#step-2-render-grid)

```

# Example below will also work as Grid class implements __toString method.
# Note that you can't forward Exceptions through __toString method on account of PHP limitations.
# Therefore you can preliminarily render grid in debug reasons and then pass resutls to view.

# or shorter

# or using blade syntax (Laravel 5)
{!! $grid !!}

```

#### Notes

[](#notes)

- Class names in example code used without namespaces therefore you must import it before
- Grids does not includes Twitter Bootstrap css/js files to your layout. You need to do it manually Quick links:

```

```

- Centeron\\Grids\\Components\\Pager component works only with Laravel 4.X, for Laravel 5 use Centeron\\Grids\\Components\\Laravel5\\Pager

##### Working with related Eloquent models

[](#working-with-related-eloquent-models)

If you need to render data from related Eloquent models, the recommendation is to use joins instead of fetching data from related models becouse in this case filters/sorting will not work. Grids sorting and filters changes Laravel query object, but Laravel makes additional queries to get data for related models, so it's impossible to use filters/sorting with related models.

Following example demonstrates, how to construct grid that displays data from Customer model and related Country model.

```
// building query with join
$query = Customer
    ::leftJoin('countries', 'customers.country_id', '=','countries.id' )
    ->select('customers.*')
    // Column alias 'country_name' used to avoid naming conflicts, suggest that customers table also has 'name' column.
    ->addSelect('countries.name as country_name')
...
///   "Country" column config:
	(new FieldConfig)
	        /// Grid column displaying country name must be named according to SQl alias: column_name
		->setName('country_name')
		->setLabel('Country')
		// If you use MySQL, grid filters for column_name in this case may not work,
		// becouse MySQL don't allows to specify column aliases in WHERE SQL section.
		// To fix filtering for aliased columns, you need to override
		// filtering function to use 'countries.name' in SQL instead of 'country_name'
		->addFilter(
			(new FilterConfig)
				->setOperator(FilterConfig::OPERATOR_EQ)
				->setFilteringFunc(function($val, EloquentDataProvider $provider) {
					$provider->getBuilder()->where('countries.name', '=', $val);
				})
		)
		// Sorting will work by default becouse MySQL allows to use column aliases in ORDER BY SQL section.
		->setSortable(true)
	,
...
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 91.6% 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 ~23 days

Recently: every ~310 days

Total

90

Last Release

2163d ago

Major Versions

v0.9.11 → v1.0.02016-01-14

v0.9.12 → v1.1.02016-01-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a1de0c2d30fcc0db469a5ca9c983cd6d2fe6219e5b8a400b43d956f10371bdb?d=identicon)[centeron](/maintainers/centeron)

---

Top Contributors

[![Nayjest](https://avatars.githubusercontent.com/u/153999?v=4)](https://github.com/Nayjest "Nayjest (349 commits)")[![SuperQcid](https://avatars.githubusercontent.com/u/5107484?v=4)](https://github.com/SuperQcid "SuperQcid (6 commits)")[![globotech-acc](https://avatars.githubusercontent.com/u/10062496?v=4)](https://github.com/globotech-acc "globotech-acc (5 commits)")[![asaf050](https://avatars.githubusercontent.com/u/7129342?v=4)](https://github.com/asaf050 "asaf050 (4 commits)")[![hackel](https://avatars.githubusercontent.com/u/583677?v=4)](https://github.com/hackel "hackel (4 commits)")[![centeron](https://avatars.githubusercontent.com/u/33687144?v=4)](https://github.com/centeron "centeron (4 commits)")[![cpttripzz](https://avatars.githubusercontent.com/u/4466445?v=4)](https://github.com/cpttripzz "cpttripzz (2 commits)")[![imerr](https://avatars.githubusercontent.com/u/1426904?v=4)](https://github.com/imerr "imerr (2 commits)")[![wdog](https://avatars.githubusercontent.com/u/7026919?v=4)](https://github.com/wdog "wdog (1 commits)")[![crapougnax](https://avatars.githubusercontent.com/u/1242077?v=4)](https://github.com/crapougnax "crapougnax (1 commits)")[![et-nik](https://avatars.githubusercontent.com/u/3670640?v=4)](https://github.com/et-nik "et-nik (1 commits)")[![github-4-work](https://avatars.githubusercontent.com/u/23081744?v=4)](https://github.com/github-4-work "github-4-work (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")

---

Tags

laraveldatabaseeloquentgridlaravel 5laravel5bootstraptablescenteron

### Embed Badge

![Health badge](/badges/centeron-laravel-grids/health.svg)

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

###  Alternatives

[nayjest/grids

Grids for Laravel 4 &amp; Laravel 5 frameworks

200152.0k1](/packages/nayjest-grids)

PHPackages © 2026

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