PHPackages                             mmucklo/grid-bundle - 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. [Admin Panels](/categories/admin)
4. /
5. mmucklo/grid-bundle

ActiveSymfony-bundle[Admin Panels](/categories/admin)

mmucklo/grid-bundle
===================

Datagrid for symfony2 or symfony3 or symfony4 or symfony5

7.3.0(5y ago)20347.1k↓29.2%11[12 issues](https://github.com/mmucklo/DtcGridBundle/issues)[1 PRs](https://github.com/mmucklo/DtcGridBundle/pulls)3MITPHPPHP &gt;=5.6.0CI failing

Since Jan 27Pushed 1w ago4 watchersCompare

[ Source](https://github.com/mmucklo/DtcGridBundle)[ Packagist](https://packagist.org/packages/mmucklo/grid-bundle)[ RSS](/packages/mmucklo-grid-bundle/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (17)Versions (59)Used By (3)

DtcGridBundle
=============

[](#dtcgridbundle)

[![CI](https://github.com/mmucklo/DtcGridBundle/actions/workflows/ci.yml/badge.svg)](https://github.com/mmucklo/DtcGridBundle/actions/workflows/ci.yml)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/54f8d7426b5cb515eb512107024c56e9b9ec55940e7d88713bb88542e21a9507/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6d75636b6c6f2f4474634772696442756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mmucklo/DtcGridBundle/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/9740bd5fc227eee0e3db3a36f6aa5032729115f2edd54a0ff1c8e0525cf6d3e8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6d75636b6c6f2f4474634772696442756e646c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mmucklo/DtcGridBundle/?branch=master)

Generate a searchable Grid from a Doctrine ORM Entity or Doctrine MongoDB Document

- Utilize jQuery [DataTables](https://datatables.net), [jqGrid](http://www.trirand.com/blog/)(\*), or a Styled HTML Table(\*)
- Easily styled using Bootstrap
- Customize columns and more...
- (new as of 2.0): Easy to install, easy get started

(\*) search functionality supported on DataTables only

Render customizable tables using jqGrid, or jQuery DataTables, or in a Styled HTML Table.

Supports both Doctrine ORM and Doctrine MongoDB ODM

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

[](#requirements)

PHPSymfony (tested)7.23.4 - 4.4 LTS7.33.4 - 5.4 LTS7.43.4 - 5.4 LTS8.05.4 - 6.4 LTS8.15.4 - 6.4 LTS8.25.4 - 6.4 LTS8.35.4 - 7.4 LTS8.45.4 - 8.0The bundle declares support for Symfony `^3.4 || ^4.4 || ^5.4 || ^6.0 || ^7.0 || ^8.0`. Composer will pick the highest Symfony version your PHP supports.

[![Screenshot](/Resources/doc/img/screenshot.png?raw=true "Screenshot")](/Resources/doc/img/screenshot.png?raw=true)

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

[](#installation)

### Symfony 4/5

[](#symfony-45)

```
    composer.phar require mmucklo/grid-bundle

```

You may see something like this (please answer 'y' to the question if prompted):

```
  -  WARNING  mmucklo/grid-bundle (>=5.0): From github.com/symfony/recipes-contrib:master
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/mmucklo/grid-bundle/4.0

    Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n): y
  - Configuring mmucklo/grid-bundle (>=5.0): From github.com/symfony/recipes-contrib:master

```

### Symfony 2/3

[](#symfony-23)

Add this to your AppKernel.php file:

```
    public function registerBundles()
    {
        $bundles = [
            ...
            new \Dtc\GridBundle\DtcGridBundle(),
            ...
        ]
```

Add this to your app/config/routing.yml file:

```
dtc_grid:
    resource: '@DtcGridBundle/Resources/config/routing.yml'
```

Usage
-----

[](#usage)

### Get Started

[](#get-started)

After installation, all entities and documents that have a Grid annotation should be available off the dtc\_grid route:

(NOTE: symfony5 example below, for symfony2/3, the namespace for the class may be different - e.g. AppBundle instead of App)

There are two recommended ways to setup a grid for a page, through Annotations, or through Reflection

#### Reflection

[](#reflection)

Automatic Grid setup is possible by setting the reflections: allowed\_entities: \[...\] parameter in the config/packages/dtc\_grid.yaml configuration file (or config.yml for symfony &lt;= 3.4)

```
dtc_grid:
    reflection:
        # allow any entity to be shown via the /dtc_grid route
        # allowed_entities: ~, '*', or an array of entity names [ 'App:Product', 'App:Category', ... ]
        #  ~ - no entities allowed for reflection
        #  * - all entities allowed for reflection
        #  [ 'App:Product', 'App:Category' ] - only App:Product and App:Category allowed
        allowed_entities: ~
```

#### (New in 6.0) grid yaml file definition

[](#new-in-60-grid-yaml-file-definition)

You can place the grid column definitions in a custom yaml file:

##### Step 1 - create the yaml file:

[](#step-1---create-the-yaml-file)

```
# File location(s):
#   - symfony 4+: config/dtc_grid/*.yaml (will load all *.yaml files in this directory)
#   - symfony 2/3: src/*/*/Resources/config/dtc_grid.yaml (will only load files with this name or the name 'dtc_grid.yml')
#   - custom (bundles): add the following to a CompilerPass:
#        # $cacheDir = $container->getParameter('kernel.cache_dir');
#        \Dtc\GridBundle\Grid\Source\ColumnSource::cacheClassesFromFile($cacheDir, $filename);
App\User:
  columns:
    id:
      sortable: true
    username:
      sortable: true
      searchable: true
    email:
      searchable: true
    createdAt:
      sortable: true
    updatedAt:
      sortable: true
    status:
      sortable: true
      searchable: true
  actions:
    -
      label: Show
      type: show
      route: dtc_grid_show
    -
      label: Archive
      type: delete
      route: dtc_grid_delete
  sort:
    id: ASC

App\Article:
  columns:
    id:
      sortable: true
    userId:
      sortable: true
    createdAt:
      sortable: true
    updatedAt:
      sortable: true
    subject:
      searchable: true
    status:
      sortable: true
  actions:
    -
      label: Show
      type: show
      route: dtc_grid_show
    -
      label: Custom
      onclick: "alert('custom action')"
      button_class: btn-info
  sort:
    createdAt: DESC
```

#### Annotation Simple Example

[](#annotation-simple-example)

Note: this example still uses reflection to discover the columns, however if you want to customize the columns shown, and even which ones are shown, read on below in the section titled Customize Columns

```
