Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pedro-teixeira/grid-bundle
A Symfony2 Ajax Grid
https://github.com/pedro-teixeira/grid-bundle
ajax-grid bundle grid symfony
Last synced: 18 days ago
JSON representation
A Symfony2 Ajax Grid
- Host: GitHub
- URL: https://github.com/pedro-teixeira/grid-bundle
- Owner: pedro-teixeira
- License: mit
- Created: 2013-02-25T18:15:55.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-04-04T11:35:59.000Z (over 8 years ago)
- Last Synced: 2024-10-15T07:14:24.254Z (about 1 month ago)
- Topics: ajax-grid, bundle, grid, symfony
- Language: PHP
- Homepage: https://pedroteixeira.io
- Size: 895 KB
- Stars: 17
- Watchers: 5
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pedro-teixeira/grid-bundle
[![Build Status](http://img.shields.io/travis/pedro-teixeira/grid-bundle.svg?style=flat)](https://travis-ci.org/pedro-teixeira/grid-bundle) [![Version](http://img.shields.io/packagist/v/pedro-teixeira/grid-bundle.svg?style=flat)](https://packagist.org/packages/pedro-teixeira/grid-bundle) [![Downloads](http://img.shields.io/packagist/dt/pedro-teixeira/grid-bundle.svg?style=flat)](https://packagist.org/packages/pedro-teixeira/grid-bundle) [![License](http://img.shields.io/packagist/l/pedro-teixeira/grid-bundle.svg?style=flat)](https://packagist.org/packages/pedro-teixeira/grid-bundle)
> Ajax grid for Symfony2
## Example
![](https://github.com/pedro-teixeira/grid-bundle/blob/master/Resources/doc/usage.gif)
*Using [Twitter Bootstrap](http://twitter.github.com/bootstrap/), [jQuery Bootstrap Datepicker](http://www.eyecon.ro/bootstrap-datepicker/) and fake data with [Faker](https://github.com/fzaninotto/faker).*
## Requirements
1. [Twitter Bootstrap](http://twitter.github.com/bootstrap/) (not mandatory)
* If you choose to don't use Twitter Bootstrap, it'll be necessary to create your own style.
2. [jQuery Bootstrap Datepicker](http://www.eyecon.ro/bootstrap-datepicker/) (not mandatory)
* If you choose to don't use Bootstrap Datepicker, please disable the datepicker as default in the configuration, "use_datepicker".## Installation
1. **Add as a dependency in your composer file**
```json
"require": {
"pedro-teixeira/grid-bundle":"dev-master"
}
```2. **Add to your Kernel**
```php
// application/ApplicationKernel.php
public function registerBundles()
{
$bundles = array(
new PedroTeixeira\Bundle\GridBundle\PedroTeixeiraGridBundle()
);
}
```3. **Add to your assetics configuration**
```yml
# application/config/config.yml
assetic:
bundles: [ PedroTeixeiraGridBundle ]
```4. **Add assets to your layout**
```twig
{% stylesheets
'@PedroTeixeiraGridBundle/Resources/public/css/grid.css'
%}
{% endstylesheets %}
``````twig
{% javascripts
'@PedroTeixeiraGridBundle/Resources/public/js/grid.js'
%}
{% endjavascripts %}
```5. **(optional) Adjust configurations**
```yml
# application/config/config.yml
pedro_teixeira_grid:
defaults:
date:
use_datepicker: true
date_format: 'dd/MM/yy'
date_time_format: 'dd/MM/yy HH:mm:ss'
pagination:
limit: 20
export:
enabled: true
path: '/tmp/'
```The configuration "use_datepicker" will set the input type as "text" and attach a jQuery plugin "datepicker()" to the filter.
## Create your grid
1. **Create the grid class**
In your bundle, create a folder named "Grid" (or wathever namespace you want) and create your grid definition class.
```php
addColumn('Hidden Field')
->setField('hidden')
->setIndex('r.hidden')
->setExportOnly(true);$this->addColumn('ID')
->setField('id')
->setIndex('r.id')
->getFilter()
->getOperator()
->setComparisonType('equal');$this->addColumn('Created At')
->setField('createdAt')
->setIndex('r.createdAt')
->setFilterType('date_range')
->setRenderType('date');$this->addColumn('Name')
->setField('name')
->setIndex('r.name');$this->addColumn('Number')
->setField('number')
->setIndex('r.number')
->setFilterType('number_range');$this->addColumn('Options')
->setField('option')
->setIndex('r.options')
->setFilterType('select')
->getFilter()
->setOptions(array(
'key' => 'value'
));$this->addColumn('Action')
->setTwig('PedroTeixeiraTestBundle:Test:gridAction.html.twig')
->setFilterType(false);
}
}
```2. **Use the grid factory in your controller**
```php
getDoctrine()->getRepository('PedroTeixeiraTestBundle:TestEntity');
$queryBuilder = $repository->createQueryBuilder('r');/** @var \PedroTeixeira\Bundle\TestBundle\Grid\TestGrid $grid */
$grid = $this->get('pedroteixeira.grid')->createGrid('\PedroTeixeira\Bundle\TestBundle\Grid\TestGrid');
$grid->setQueryBuilder($queryBuilder);if ($grid->isResponseAnswer()) {
return $grid->render();
}return array(
'grid' => $grid->render()
);
}
}
```3. **Render in your template**
```twig
{{ pedroteixeira_grid(grid) }}
````
Or if you want to render the grid's html and the grid's js separately:
```twig
{{ pedroteixeira_grid_html(grid) }}
...
{{ pedroteixeira_grid_js(grid) }}
````
## Understanding
* [Grid](https://github.com/pedro-teixeira/grid-bundle/tree/master/Resources/doc/grid.md)
* [Column](https://github.com/pedro-teixeira/grid-bundle/tree/master/Resources/doc/column.md)
* [Render](https://github.com/pedro-teixeira/grid-bundle/tree/master/Resources/doc/column/render.md)
* [Filter](https://github.com/pedro-teixeira/grid-bundle/tree/master/Resources/doc/column/filter.md)## Continuous integration
To execute locally the checks that are executed on Travis:
```bash
composer install
find ./Grid ./DependencyInjection ./Twig -name "*.php" -exec php -l {} \;
./bin/phpcs --extensions=php --standard=PSR2 ./Grid ./DependencyInjection ./Twig
```