PHPackages                             domenik88/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. domenik88/grid-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

domenik88/grid-bundle
=====================

Datagrid for symfony4 or symfony5 with DoctrineORM after 3.0

7.2.2(5y ago)04MITPHPPHP &gt;=5.6.0

Since Jan 27Pushed 5y agoCompare

[ Source](https://github.com/Domenik88/DtcGridBundle)[ Packagist](https://packagist.org/packages/domenik88/grid-bundle)[ RSS](/packages/domenik88-grid-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (17)Versions (56)Used By (0)

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

[](#dtcgridbundle)

Generate a searchable Grid from a Doctrine ORM Entity

- 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

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

```

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:

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

```
