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

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

yetisolucoes/grids
==================

Grids for Laravel 5 frameworks

v1.3.8.1(7y ago)027MITPHPPHP &gt;=5.4.0

Since Aug 26Pushed 7y agoCompare

[ Source](https://github.com/yetisolucoes/Grids)[ Packagist](https://packagist.org/packages/yetisolucoes/grids)[ Docs](https://github.com/Nayjest/Grids)[ RSS](/packages/yetisolucoes-grids/feed)WikiDiscussions master Synced yesterday

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

Grids
=====

[](#grids)

### `Data Grids Framework for Laravel`

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

[![Codacy Badge](https://camo.githubusercontent.com/8f5622b3274264b4d267d1f22b3933924e3f66af8c49e04be3a6dc2ea9df110e/68747470733a2f2f7777772e636f646163792e636f6d2f70726f6a6563742f62616467652f3463363935356461343636613435633161363439373262626662383166636237)](https://www.codacy.com/public/mail_2/Grids)[![Code Climate](https://camo.githubusercontent.com/73787ec0fb91b17e1340e818112dd8166b5369d22b625a4577b40ae9dcef9f53/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4e61796a6573742f47726964732f6261646765732f6770612e737667)](https://codeclimate.com/github/Nayjest/Grids)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a325e54d198e7baaf7c287f27240c155fa6c5760eca861c673b67f2fe7cad230/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e61796a6573742f47726964732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Nayjest/Grids/?branch=master)[![Circle CI](https://camo.githubusercontent.com/31d2246bea0aa28ac9ba9470dcee7033e2f04ac924e4f5fdce23e6374bd58d50/68747470733a2f2f636972636c6563692e636f6d2f67682f4e61796a6573742f47726964732f747265652f6d61737465722e7376673f7374796c653d737667)](https://circleci.com/gh/Nayjest/Grids/tree/master)[![Release](https://camo.githubusercontent.com/6f2c64f90b774101ab18edc16d0cef7f9bbbb4ae4089f94e148f1090df07875e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e61796a6573742f67726964732e737667)](https://packagist.org/packages/nayjest/grids)[![HHVM Status](https://camo.githubusercontent.com/899648fd10c504dc059182b99817780f4ec1ef28ccaf5a4526173b3b1530c816/687474703a2f2f6868766d2e683463632e64652f62616467652f6e61796a6573742f67726964732e737667)](http://hhvm.h4cc.de/package/nayjest/grids)[![Join the chat at https://gitter.im/Nayjest/Grids](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/Nayjest/Grids?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Both Laravel 4 and Laravel 5 are supported.

**Announcement: Further development moved to [view-components/grids](https://github.com/view-components/grids).** view-components/grids package is framework-agnostic, but it's easy to integrate with Laravel using [view-components/eloquent-data-processing](https://github.com/view-components/eloquent-data-processing) package.

- If you need stability, use nayjest/grids
- If you need more features and flexibility, try view-components/grids
- Pull-requests from 3rd-party contributors containing new features can be accepted to nayjest/grids just in case when it doesn't break backward compatibility. If you have some radical improvements, please contribute to view-components/grids.

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
- 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

Upcoming Features (moved to view-components/grids)
--------------------------------------------------

[](#upcoming-features-moved-to-view-componentsgrids)

- Autodetecting columns based on Eloquent model (if not specified)
- Builtin output formatters for different column types
- Working with json data sources via ajax
- Check compatibility with Lumen microframework

[Ask for more features](https://github.com/Nayjest/Grids/issues). You are welcome!

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 nayjest/grids to "require" section of your composer.json

```
"require": {
    "nayjest/grids": "^1.3.1"
},
```

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

```
"require": {
    "nayjest/grids": "^1.3.1",
    "laravelcollective/html": "^5"
},
```

Then install dependencies using following command:

```
php composer.phar install
```

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

For Laravel 4

```
php composer.phar require nayjest/grids
```

For Laravel 5

```
php composer.phar require nayjest/grids laravelcollective/html
```

##### Step 2: Laravel Setup

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

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

```
'Nayjest\Grids\ServiceProvider',
```

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

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

You may also add facade aliases to your application configuration:

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

Demo
----

[](#demo)

Demonstration available [here](http://grids-demo.herokuapp.com/demo/example4)

[Code](https://github.com/Nayjest/grids-demo)

Usage
-----

[](#usage)

#### Basic example

[](#basic-example)

In example below grid is configured by php array using [Nayjest/Builder](https://github.com/Nayjest/Builder) package facilities.

```
$cfg = [
    'src' => 'App\User',
    'columns' => [
            'id',
            'name',
            'email',
            'country'
    ]
];
echo Grids::make($cfg);
```

Results available [here](http://grids-demo.herokuapp.com/demo/example1). For more details see [demo application repository](https://github.com/Nayjest/grids-demo/blob/master/app/Http/Controllers/DemoController.php)

#### Advanced example

[](#advanced-example)

If you don't like plain arrays, you can construct grids using object oriented api:

##### 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:

```

```

- Nayjest\\Grids\\Components\\Pager component works only with Laravel 4.X, for Laravel 5 use Nayjest\\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)
	,
...
```

Upgrade Guide
-------------

[](#upgrade-guide)

### From 0.9.X to 1.X

[](#from-09x-to-1x)

There are full backward compatibility between 0.9.X and 1.X branches.

### From 0.8.X to 0.9.X

[](#from-08x-to-09x)

Grids starting from v 0.9.0 uses "laravelcollective\\html" instead of outdated "illuminate\\html".

You may continue to use illuminate\\html, but it's recommended to replace it to laravelcollective\\html.

1. Replace illuminate\\html to laravelcollective\\html in composer.json
2. Replace class aliases section in config/app.php ('Illuminate\\Html\\HtmlFacade' to 'Collective\\Html\\FormFacade' and 'Illuminate\\Html\\HtmlFacade' to 'Collective\\Html\\HtmlFacade')
3. Replace 'Illuminate\\Html\\HtmlServiceProvider' to 'Collective\\Html\\HtmlServiceProvider'
4. Run composer update

### From 0.3.X to 0.4.X

[](#from-03x-to-04x)

1. Use THead &amp; TFoot instead of Header &amp; Footer components
2. If you have customized grid view (grid.php), refactor it using changes in default view
3. Some components became default, so you don't need to add it to configuration

Default components hierarchy:

```
- GridConfig
    - THead
        - ColumnHeadersRow
        - FiltersRow
    - TFoot
        - OneCellRow
            - Pager

```

For adding child components to default one, resolve it by name and use addComponent / addComponents methods.

Example:

```
...
(new GridConfig)
    ->setDataProvider($provider)
    ->getComponentByName(THead::NAME)
        ->getComponentByName(FiltersRow::NAME)
            ->addComponent(
                (new HtmlTag)
                    ->setTagName('button')
                    ->setContent('Filter')
                    ->setAttributes([
                        'type' => 'submit',
                        'class' => 'btn btn-success btn-sm'
                    ])
                    ->setRenderSection('filters_row_column_Actions')
            )
            ->getParent()
        ->getParent()
    ->setColumns([
...
```

Note that setComponents method rewrites components structure provided by defaults.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

© 2014—2017 Vitalii Stepanenko

Licensed under the MIT License.

Please see [License File](LICENSE) for more information.

[![Flag Counter](https://camo.githubusercontent.com/738e9855820160028b2d7f3384763cea81f3326116e108d71848bf9368961202/687474703a2f2f7330372e666c6167636f756e7465722e636f6d2f636f756e742f304c41622f62675f4646464646462f7478745f3030303030302f626f726465725f4646464646462f636f6c756d6e735f382f6d6178666c6167735f382f766965776572735f302f6c6162656c735f302f7061676576696577735f302f666c6167735f302f70657263656e745f312f)](http://info.flagcounter.com/0LAb)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 90.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 ~17 days

Recently: every ~193 days

Total

88

Last Release

2780d ago

Major Versions

v0.9.12 → v1.0.02016-01-14

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43795109?v=4)[yetisolucoes](/maintainers/yetisolucoes)[@yetisolucoes](https://github.com/yetisolucoes)

---

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)")[![diegobentes](https://avatars.githubusercontent.com/u/30333916?v=4)](https://github.com/diegobentes "diegobentes (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)")[![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)")[![yetisolucoes](https://avatars.githubusercontent.com/u/43795109?v=4)](https://github.com/yetisolucoes "yetisolucoes (2 commits)")[![wdog](https://avatars.githubusercontent.com/u/7026919?v=4)](https://github.com/wdog "wdog (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![github-4-work](https://avatars.githubusercontent.com/u/23081744?v=4)](https://github.com/github-4-work "github-4-work (1 commits)")[![et-nik](https://avatars.githubusercontent.com/u/3670640?v=4)](https://github.com/et-nik "et-nik (1 commits)")[![crapougnax](https://avatars.githubusercontent.com/u/1242077?v=4)](https://github.com/crapougnax "crapougnax (1 commits)")

---

Tags

laraveldatabasehtmleloquentgridlaravel 5laravel5bootstraptables

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/yetisolucoes-grids/health.svg)](https://phpackages.com/packages/yetisolucoes-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)
