├── Makefile
├── Resources
├── views
│ ├── Page
│ │ ├── table.html.twig
│ │ ├── jq_grid.html.twig
│ │ └── datatables.html.twig
│ ├── Grid
│ │ ├── jq_grid.html.twig
│ │ ├── table.html.twig
│ │ └── datatables.html.twig
│ ├── layout_base_jquery.html.twig
│ └── layout.html.twig
├── translations
│ ├── dtc_grid.zh_CN.yaml
│ ├── dtc_grid.zh_TW.yaml
│ ├── dtc_grid.da.yaml
│ ├── dtc_grid.vi.yaml
│ ├── dtc_grid.en.yaml
│ ├── dtc_grid.es.yaml
│ ├── dtc_grid.fi.yaml
│ ├── dtc_grid.is.yaml
│ ├── dtc_grid.it.yaml
│ ├── dtc_grid.no.yaml
│ ├── dtc_grid.pl.yaml
│ ├── dtc_grid.sv.yaml
│ ├── dtc_grid.ta.yaml
│ ├── dtc_grid.cs.yaml
│ ├── dtc_grid.et.yaml
│ ├── dtc_grid.hi.yaml
│ ├── dtc_grid.hu.yaml
│ ├── dtc_grid.nl.yaml
│ ├── dtc_grid.pt_BR.yaml
│ ├── dtc_grid.pt_PT.yaml
│ ├── dtc_grid.uk.yaml
│ ├── dtc_grid.gr.yaml
│ ├── dtc_grid.ro.yaml
│ ├── dtc_grid.ru.yaml
│ ├── dtc_grid.de.yaml
│ └── dtc_grid.fr.yaml
├── doc
│ ├── img
│ │ └── screenshot.png
│ ├── CustomizeCell.md
│ ├── GridSource.md
│ ├── intro.md
│ ├── TableRenderer.md
│ ├── GridColumns.md
│ ├── jqGridRenderer.md
│ └── DatatablesRenderer.md
├── public
│ ├── js
│ │ ├── datatables
│ │ │ ├── main.js
│ │ │ ├── action.js
│ │ │ └── jquery.dtc_grid_datatables.js
│ │ └── jq_grid
│ │ │ └── main.js
│ └── css
│ │ └── datatables
│ │ └── datatables.css
├── skeleton
│ ├── grid_template.html.twig
│ ├── GridColumns.php.twig
│ └── controller.php.twig
├── config
│ ├── routing.yml
│ ├── grid.yml
│ └── dtc_grid.yaml
└── meta
│ └── LICENSE
├── Annotation
├── Annotation.php
├── ShowAction.php
├── DeleteAction.php
├── Sort.php
├── Action.php
├── Grid.php
└── Column.php
├── phpunit.xml
├── Grid
├── Source
│ ├── ColumnSourceInfo.php
│ ├── AbstractDoctrineGridSource.php
│ ├── GridSourceInterface.php
│ ├── AbstractGridSource.php
│ ├── DocumentGridSource.php
│ ├── EntityGridSource.php
│ └── ColumnSource.php
├── Pager
│ ├── Pager.php
│ └── GridSourcePager.php
├── Renderer
│ ├── AbstractJqueryRenderer.php
│ ├── TableGridRenderer.php
│ ├── AbstractRenderer.php
│ ├── JQGridRenderer.php
│ ├── RendererFactory.php
│ └── DataTablesRenderer.php
└── Column
│ ├── TwigBlockGridColumn.php
│ ├── AbstractGridColumn.php
│ ├── ActionGridColumn.php
│ └── GridColumn.php
├── .gitignore
├── .scrutinizer.yml
├── Tests
├── Grid
│ └── Source
│ │ └── TestGridSource.php
├── Util
│ └── CamelCaseTest.php
└── Manager
│ └── GridSourceManagerTest.php
├── Util
├── CamelCase.php
└── ColumnUtil.php
├── DtcGridBundle.php
├── Command
├── SourceListCommand.php
└── GenerateGridSourceCommand.php
├── Generator
├── Generator.php
└── GridSourceGenerator.php
├── LICENSE
├── Twig
└── Extension
│ ├── TwigExtensionLegacy.php
│ └── TwigExtension.php
├── Mapper
└── ArrayValueObject.php
├── composer.json
├── .travis.yml
├── DependencyInjection
├── Configuration.php
├── DtcGridExtension.php
└── Compiler
│ └── GridSourceCompilerPass.php
├── Controller
└── GridController.php
├── Manager
└── GridSourceManager.php
└── CHANGELOG.md
/Makefile:
--------------------------------------------------------------------------------
1 | cs-fix:
2 | bin/php-cs-fixer fix . --rules=@PSR2,@Symfony
3 |
--------------------------------------------------------------------------------
/Resources/views/Page/table.html.twig:
--------------------------------------------------------------------------------
1 | {% extends '@DtcGrid/layout.html.twig' %}
2 |
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.zh_CN.yaml:
--------------------------------------------------------------------------------
1 | refresh: "刷新"
2 | save: "保存更改"
3 | close: "关闭"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.zh_TW.yaml:
--------------------------------------------------------------------------------
1 | close: "關閉"
2 | save: "儲存變更"
3 | refresh: "重新整理"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.da.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Opdatere"
2 | save: "Gem ændringer"
3 | close: "Luk"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.vi.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Làm mới"
2 | save: "Lưu thay đổi"
3 | close: "Đóng"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.en.yaml:
--------------------------------------------------------------------------------
1 | close: "Close"
2 | save: "Save Changes"
3 | refresh: "Refresh"
4 |
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.es.yaml:
--------------------------------------------------------------------------------
1 | save: "Guardar Cambios"
2 | refresh: "Actualizar"
3 | close: "Cerrar"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.fi.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Päivitä"
2 | save: "Tallenna muutokset"
3 | close: "Sulje"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.is.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Uppfæra"
2 | save: "Vista Breytingar"
3 | close: "Loka"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.it.yaml:
--------------------------------------------------------------------------------
1 | save: "Salva Modifiche"
2 | close: "Chiudi"
3 | refresh: "Aggiornare"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.no.yaml:
--------------------------------------------------------------------------------
1 | save: "Lagre endringar"
2 | close: "Lukk"
3 | refresh: "Oppdater"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.pl.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Odświeżyć"
2 | close: "Zamknij"
3 | save: "Zapisz Zmiany"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.sv.yaml:
--------------------------------------------------------------------------------
1 | close: "Stäng"
2 | refresh: "Uppdatera"
3 | save: "Spara ändringar"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.ta.yaml:
--------------------------------------------------------------------------------
1 | refresh: "புதுப்பி"
2 | close: "மூடும்"
3 | save: "மாற்றங்களைச் சேமி"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.cs.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Aktualizovat"
2 | close: "Zavřít"
3 | save: "Uložit Změny"
4 |
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.et.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Värskendama"
2 | save: "Salvesta Muudatused"
3 | close: "Sule"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.hi.yaml:
--------------------------------------------------------------------------------
1 | close: "बंद करें"
2 | save: "परिवर्तन सहेजें"
3 | refresh: "ताज़ा करें"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.hu.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Frissítés"
2 | close: "Bezárás"
3 | save: "Módosítások Mentése"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.nl.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Vernieuwen"
2 | save: "Wijzigingen Opslaan"
3 | close: "Sluiten"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.pt_BR.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Atualizar"
2 | close: "Fechar"
3 | save: "Salvar Alterações"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.pt_PT.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Atualizar"
2 | close: "Fechar"
3 | save: "Guardar Alterações"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.uk.yaml:
--------------------------------------------------------------------------------
1 | save: "Зберегти зміни"
2 | refresh: "Оновлювати"
3 | close: "Закрити"
4 |
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.gr.yaml:
--------------------------------------------------------------------------------
1 | refresh: "Ανανεώνω"
2 | save: "Αποθήκευση Αλλαγών"
3 | close: "Κλείσιμο"
4 |
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.ro.yaml:
--------------------------------------------------------------------------------
1 | save: "Salvare Modificări"
2 | close: "Închidere"
3 | refresh: "Reîmprospăta"
--------------------------------------------------------------------------------
/Resources/translations/dtc_grid.ru.yaml:
--------------------------------------------------------------------------------
1 | save: "Сохранить изменения"
2 | close: "Закрыть"
3 | refresh: "Обновить"
4 |
--------------------------------------------------------------------------------
/Annotation/Annotation.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Tests
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Grid/Source/ColumnSourceInfo.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
16 |
--------------------------------------------------------------------------------
/Grid/Pager/Pager.php:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 | {% endblock %}
--------------------------------------------------------------------------------
/Resources/config/routing.yml:
--------------------------------------------------------------------------------
1 | dtc_grid:
2 | path: /dtc_grid/grid
3 | defaults: { _controller: dtc_grid.controller.grid::grid }
4 |
5 | dtc_grid_data:
6 | path: /dtc_grid/data
7 | defaults: { _controller: dtc_grid.controller.grid::data }
8 |
9 | dtc_grid_show:
10 | path: /dtc_grid/show
11 | defaults: { _controller: dtc_grid.controller.grid::show }
12 |
13 | dtc_grid_delete:
14 | path: /dtc_grid/delete
15 | defaults: { _controller: dtc_grid.controller.grid::delete }
16 |
--------------------------------------------------------------------------------
/DtcGridBundle.php:
--------------------------------------------------------------------------------
1 | addCompilerPass(new GridSourceCompilerPass());
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Annotation/Action.php:
--------------------------------------------------------------------------------
1 |
15 | */
16 | public $actions;
17 |
18 | /**
19 | * @var \Dtc\GridBundle\Annotation\Sort
20 | */
21 | public $sort;
22 |
23 | /**
24 | * @var array<\Dtc\GridBundle\Annotation\Sort>
25 | */
26 | public $sortMulti;
27 | }
28 |
--------------------------------------------------------------------------------
/Grid/Source/AbstractDoctrineGridSource.php:
--------------------------------------------------------------------------------
1 | objectManager = $objectManager;
14 | $this->objectName = $objectName;
15 | }
16 |
17 | public function setIdColumn($idColumn)
18 | {
19 | $this->idColumn = $idColumn;
20 | }
21 |
22 | public function hasIdColumn()
23 | {
24 | return $this->idColumn ? true : false;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Annotation/Column.php:
--------------------------------------------------------------------------------
1 | loadTemplate('{{ template_name }}');
17 | $env = $twig->getGlobals();
18 |
19 | {% for field, title in fields -%}
20 | $col = new TwigBlockGridColumn('{{ field }}', '{{ title }}', $template, $env);
21 | $col->setOption('width', 75);
22 | $columns[] = $col;
23 |
24 | {% endfor -%}
25 | parent::__construct($columns);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Resources/views/Grid/table.html.twig:
--------------------------------------------------------------------------------
1 | {% import _self as selfMacros %}
2 |
3 |
4 |
5 |
6 | {% for column in columns %}
7 | |
8 | {{ column.getLabel() }}
9 | |
10 | {% endfor %}
11 |
12 |
13 |
14 | {% for record in records %}
15 |
16 | {% for column in columns %}
17 | |
18 | {{ column.format(record, source) | raw }}
19 | |
20 | {% endfor %}
21 |
22 | {% endfor %}
23 |
24 |
25 |
26 | {% macro render_attb(attributes) %}
27 | {% for attb, value in attributes %}
28 | {{ attb }}="{{ value }}"
29 | {% endfor %}
30 | {% endmacro %}
--------------------------------------------------------------------------------
/Grid/Renderer/AbstractJqueryRenderer.php:
--------------------------------------------------------------------------------
1 | purl;
13 | }
14 |
15 | public function setPurl($purl)
16 | {
17 | $this->purl = $purl;
18 | }
19 |
20 | public function getJQuery()
21 | {
22 | return $this->jQuery;
23 | }
24 |
25 | public function setJQuery(array $jQuery)
26 | {
27 | $this->jQuery = $jQuery;
28 | }
29 |
30 | public function getParams(array &$params = null)
31 | {
32 | parent::getParams($params);
33 | $params['dtc_grid_jquery'] = $this->jQuery;
34 | $params['dtc_grid_purl'] = $this->purl;
35 |
36 | return $params;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Grid/Pager/GridSourcePager.php:
--------------------------------------------------------------------------------
1 | gridSource = $gridSource;
15 | }
16 |
17 | public function getCurrentPage()
18 | {
19 | $limit = $this->gridSource->getLimit();
20 | $offset = $this->gridSource->getOffset();
21 |
22 | if (!$limit) {
23 | return $offset;
24 | }
25 |
26 | return ceil(($offset / $limit) + 1);
27 | }
28 |
29 | public function getTotalPages()
30 | {
31 | $limit = $this->gridSource->getLimit();
32 | if (!$limit) {
33 | return $this->gridSource->getCount();
34 | }
35 |
36 | return ceil($this->gridSource->getCount() / $limit);
37 | }
38 |
39 | public function getRange($delta)
40 | {
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Resources/public/css/datatables/datatables.css:
--------------------------------------------------------------------------------
1 | /**
2 | * https://stephanwagner.me/only-css-loading-spinner
3 | * MIT Licensed
4 | */
5 | @keyframes dtc-grid-spinner {
6 | to {transform: rotate(360deg);}
7 | }
8 |
9 | table.dataTable td {
10 | word-wrap: break-word;
11 | word-break: break-all;
12 | }
13 |
14 | .dtc-grid-spinner:before {
15 | content: '';
16 | box-sizing: border-box;
17 | position: absolute;
18 | top: 50%;
19 | left: 50%;
20 | width: 30px;
21 | height: 30px;
22 | margin-top: -15px;
23 | margin-left: -15px;
24 | border-radius: 50%;
25 | border: 1px solid #ccc;
26 | border-top-color: #07d;
27 | animation: dtc-grid-spinner .6s linear infinite;
28 | }
29 |
30 | table.dataTable .btn {
31 | margin: 5px 0;
32 | }
33 |
34 | .dtc-grid-hidden {
35 | display: none;
36 | }
37 |
38 | /**
39 | * https://datatables.net/forums/discussion/50132/bootstrap-4-styling-issue-from-examples-page/p1?new=1
40 | */
41 | table.dataTable.table-bordered {
42 | border-collapse: collapse !important;
43 | }
--------------------------------------------------------------------------------
/Grid/Source/GridSourceInterface.php:
--------------------------------------------------------------------------------
1 | setName('dtc:grid:source:list')
23 | ->setDescription('List avaliable Grid Sources')
24 | ;
25 | }
26 |
27 | public function setGridSourceManager(GridSourceManager $gridSourceManager)
28 | {
29 | $this->gridSourceManager = $gridSourceManager;
30 | }
31 |
32 | protected function execute(InputInterface $input, OutputInterface $output)
33 | {
34 | $gridSources = $this->gridSourceManager->all();
35 |
36 | $output->writeln('Avaliable Grid Sources: ');
37 | foreach ($gridSources as $id => $source) {
38 | $output->writeln("{$id} => ".get_class($source));
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Generator/Generator.php:
--------------------------------------------------------------------------------
1 | true,
15 | 'cache' => false,
16 | 'strict_variables' => true,
17 | 'autoescape' => false,
18 | ]);
19 |
20 | return $environment->render($template, $parameters);
21 | }
22 | throw new \Exception("Class not found: Twig\Environment");
23 | }
24 |
25 | protected function renderFile($skeletonDir, $template, $target, $parameters)
26 | {
27 | $output = $this->render($skeletonDir, $template, $parameters);
28 |
29 | return $this->saveFile($target, $output);
30 | }
31 |
32 | protected function saveFile($target, $output)
33 | {
34 | if (!is_dir(dirname($target))) {
35 | mkdir(dirname($target), 0777, true);
36 | }
37 |
38 | return file_put_contents($target, $output);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016-2017 Matthew J. Mucklo
2 | Copyright (c) 2012-2015 David Tee
3 | Copyright (c) 2004-2017 Fabien Potencier (for code taken from symfony/symfony and sensio/generator-bundle)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/Resources/views/Page/jq_grid.html.twig:
--------------------------------------------------------------------------------
1 | {% extends '@DtcGrid/layout_base_jquery.html.twig' %}
2 |
3 | {% block dtc_grid_stylesheets %}
4 | {{ parent() }}
5 | {% for stylesheet in dtc_grid_jq_grid_css %}
6 | {% if stylesheet.url is defined %}
7 |
11 | {% else %}
12 |
13 | {% endif %}
14 | {% endfor %}
15 | {% endblock %}
16 |
17 | {% block dtc_grid_javascripts %}
18 | {{ parent() }}
19 | {% for javascript in dtc_grid_jq_grid_js %}
20 | {% if javascript.url is defined %}
21 |
25 | {% else %}
26 |
27 | {% endif %}
28 | {% endfor %}
29 | {% endblock %}
30 |
--------------------------------------------------------------------------------
/Resources/views/Page/datatables.html.twig:
--------------------------------------------------------------------------------
1 | {% extends '@DtcGrid/layout_base_jquery.html.twig' %}
2 |
3 | {% block dtc_grid_stylesheets %}
4 | {{ parent() }}
5 | {% for stylesheet in dtc_grid_datatables_css %}
6 | {% if stylesheet.url is defined %}
7 |
11 | {% else %}
12 |
13 | {% endif %}
14 | {% endfor %}
15 | {% endblock %}
16 |
17 | {% block dtc_grid_javascripts %}
18 | {{ parent() }}
19 | {% for javascript in dtc_grid_datatables_js %}
20 | {% if javascript.url is defined %}
21 |
25 | {% else %}
26 |
27 | {% endif %}
28 | {% endfor %}
29 | {% endblock %}
30 |
--------------------------------------------------------------------------------
/Resources/doc/GridSource.md:
--------------------------------------------------------------------------------
1 | Grid Source
2 | ===========
3 | The grid source is the glue between the renderer and your backend data.
4 |
5 | The base AbstractGridSource class forms the foundation on which both DocumentGridSource and EntityGridSource are built.
6 |
7 | Any of these can be overridden, or the Dtc\GridBundle\Grid\Source\GridSourceInterface.php can simply be implemented.
8 |
9 | ## Service
10 |
11 | The generator creates a GridSource service with auto-discovered or pre-populated columns.
12 |
13 | Example:
14 |
15 |
16 | XML:
17 |
18 |
19 | Odl\ShadowBundle\Documents\Character
20 | grid.source.character
21 |
22 |
23 |
24 | YAML:
25 | grid.source.user:
26 | class: Dtc\GridBundle\Grid\Source\DocumentGridSource
27 | arguments: ['@doctrine_mongodb.odm.default_document_manager', AppBundle\Document\User]
28 | tags: [{ name: dtc_grid.source }]
29 | calls: [[autoDiscoverColumns]]
30 |
31 | ## Custom Columns
32 |
33 | To use custom columns, on either
--------------------------------------------------------------------------------
/Twig/Extension/TwigExtensionLegacy.php:
--------------------------------------------------------------------------------
1 | 'format_cell',
11 | ];
12 |
13 | $funcs = [];
14 | foreach ($names as $twig => $local) {
15 | $funcs[$twig] = new \Twig_SimpleFunction($twig, [$this, $local]);
16 | }
17 |
18 | return $funcs;
19 | }
20 |
21 | public function getFilters()
22 | {
23 | $names = [
24 | 'format_cell' => 'format_cell',
25 | ];
26 |
27 | $funcs = [];
28 | foreach ($names as $twig => $local) {
29 | $funcs[$twig] = new \Twig_SimpleFilter($twig, [$this, $local]);
30 | }
31 |
32 | return $funcs;
33 | }
34 |
35 | public function getName()
36 | {
37 | return 'dtc_grid';
38 | }
39 |
40 | public function format_cell($value)
41 | {
42 | if (is_object($value)) {
43 | if ($value instanceof \DateTime) {
44 | return $value->format(\DateTime::ISO8601);
45 | }
46 |
47 | return 'object: '.get_class($value);
48 | } elseif (is_scalar($value)) {
49 | return $value;
50 | } elseif (is_array($value)) {
51 | return 'array';
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Twig/Extension/TwigExtension.php:
--------------------------------------------------------------------------------
1 | 'format_cell',
11 | ];
12 |
13 | $funcs = [];
14 | foreach ($names as $twig => $local) {
15 | $funcs[$twig] = new \Twig\TwigFunction($twig, [$this, $local]);
16 | }
17 |
18 | return $funcs;
19 | }
20 |
21 | public function getFilters()
22 | {
23 | $names = [
24 | 'format_cell' => 'format_cell',
25 | ];
26 |
27 | $funcs = [];
28 | foreach ($names as $twig => $local) {
29 | $funcs[$twig] = new \Twig\TwigFilter($twig, [$this, $local]);
30 | }
31 |
32 | return $funcs;
33 | }
34 |
35 | public function getName()
36 | {
37 | return 'dtc_grid';
38 | }
39 |
40 | public function format_cell($value)
41 | {
42 | if (is_object($value)) {
43 | if ($value instanceof \DateTime) {
44 | return $value->format(\DateTime::ISO8601);
45 | }
46 |
47 | return 'object: '.get_class($value);
48 | } elseif (is_scalar($value)) {
49 | return $value;
50 | } elseif (is_array($value)) {
51 | return 'array';
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Grid/Renderer/TableGridRenderer.php:
--------------------------------------------------------------------------------
1 | [
12 | 'class' => 'display table table-striped table-bordered small-font',
13 | ],
14 | ];
15 |
16 | protected $twig;
17 | protected $router;
18 | protected $translator;
19 | protected $options;
20 |
21 | public function __construct(Environment $twig, RouterInterface $router, $translator, array $options)
22 | {
23 | $this->translator = $translator;
24 | $this->twig = $twig;
25 | $this->router = $router;
26 | $this->options = $options;
27 | }
28 |
29 | public function render()
30 | {
31 | $params = [
32 | 'records' => $this->gridSource->getRecords(),
33 | 'columns' => $this->gridSource->getColumns(),
34 | 'options' => $this->options,
35 | 'source' => $this->gridSource,
36 | ];
37 |
38 | $template = '@DtcGrid/Grid/table.html.twig';
39 |
40 | return $this->twig->render($template, $params);
41 | }
42 |
43 | public function getParams(array &$params = null)
44 | {
45 | if (null === $params) {
46 | $params = [];
47 | }
48 | parent::getParams($params);
49 |
50 | return $params;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Mapper/ArrayValueObject.php:
--------------------------------------------------------------------------------
1 | 100) {
40 | exit();
41 | }
42 |
43 | if (is_array($data)) {
44 | if (!isset($data[$key])) {
45 | return null;
46 | } else {
47 | $data = &$data[$key];
48 | }
49 | } else {
50 | return null;
51 | }
52 | }
53 |
54 | return $data;
55 | }
56 |
57 | public function getValue()
58 | {
59 | return $this->getValueByArray(func_get_args());
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mmucklo/grid-bundle",
3 | "description": "Datagrid for symfony2 or symfony3 or symfony4 or symfony5",
4 | "keywords": ["grid", "jQGrid", "table"],
5 | "type": "symfony-bundle",
6 | "license": "MIT",
7 | "authors": [
8 | {
9 | "name": "David Tee"
10 | },
11 | {
12 | "name": "Matthew J Mucklo",
13 | "email": "mmucklo@gmail.com"
14 | }
15 | ],
16 | "require": {
17 | "php": ">=5.6.0",
18 | "symfony/framework-bundle": "2.*|3.*|4.*|5.*",
19 | "sensio/framework-extra-bundle": "2.*|3.*|4.*|5.*|6.*",
20 | "symfony/templating": "2.*|3.*|4.*|5.*",
21 | "symfony/translation": "2.*|3.*|4.*|5.*",
22 | "symfony/twig-bundle": "2.*|3.*|4.*|5.*",
23 | "twig/twig": "^1.0||^2.0|^3.0"
24 | },
25 | "require-dev": {
26 | "doctrine/orm": "^2.4",
27 | "doctrine/annotations": "<1.5",
28 | "doctrine/cache": "<1.7",
29 | "doctrine/collections": "<1.5",
30 | "doctrine/instantiator": "<1.1",
31 | "doctrine/common": "<2.8",
32 | "doctrine/dbal": "<2.6",
33 | "doctrine/mongodb-odm": "^1.1",
34 | "phpunit/phpunit": "^5.7.0",
35 | "friendsofphp/php-cs-fixer": "dev-master",
36 | "phpunit/php-code-coverage": "^4.0"
37 | },
38 | "config": {
39 | "bin-dir": "bin"
40 | },
41 | "autoload": {
42 | "psr-4": { "Dtc\\GridBundle\\": "" },
43 | "exclude-from-classmap": [
44 | "/Tests/"
45 | ]
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Grid/Column/TwigBlockGridColumn.php:
--------------------------------------------------------------------------------
1 | field = $field;
24 | $this->label = $label;
25 | $this->template = $template;
26 | $this->blockName = $blockName;
27 | $this->env = $env;
28 |
29 | if (!$this->blockName) {
30 | $this->blockName = $field;
31 | }
32 | }
33 |
34 | /**
35 | * @return $template
36 | */
37 | public function getTemplate()
38 | {
39 | return $this->template;
40 | }
41 |
42 | /**
43 | * @return $blockName
44 | */
45 | public function getBlockName()
46 | {
47 | return $this->blockName;
48 | }
49 |
50 | public function format($object, GridSourceInterface $gridSource)
51 | {
52 | if ($this->template->hasBlock($this->blockName, [])) {
53 | $this->env['obj'] = $object;
54 | $this->env['source'] = $gridSource;
55 |
56 | return $this->template->renderBlock($this->blockName, $this->env);
57 | } else {
58 | return 'No Template';
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.6
5 | - 7.0
6 | - 7.1
7 | - 7.2
8 | - 7.3
9 | - 7.4
10 |
11 | before_script:
12 | - composer self-update
13 | - (echo 'no' | pecl install redis) || true
14 | - (php -m | grep 'redis') || echo "extension = redis.so" > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/redis.ini
15 | - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]]; then echo 'no' | pecl install mongo; fi
16 | - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then pecl install mongodb; composer config "platform.ext-mongo" "1.6.16" && COMPOSER_MEMORY_LIMIT=-1 composer require alcaeus/mongo-php-adapter; fi
17 | - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then pecl install mongodb; composer config "platform.ext-mongo" "1.6.16" && COMPOSER_MEMORY_LIMIT=-1 composer require alcaeus/mongo-php-adapter; fi
18 | - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]] || [[ ${TRAVIS_PHP_VERSION:0:3} == "7.3" ]] || [[ ${TRAVIS_PHP_VERSION:0:3} == "7.4" ]]; then pecl install mongodb; echo 'extension = mongodb.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini && echo "composer config" && composer config "platform.ext-mongo" "1.6.16" && echo "composer require" && COMPOSER_MEMORY_LIMIT=-1 composer require alcaeus/mongo-php-adapter; echo "composer require done"; fi
19 | - echo "composer install"
20 | - COMPOSER_MEMORY_LIMIT=-1 composer install
21 |
22 | script:
23 | - bin/phpunit --coverage-clover=coverage.clover --log-junit=phpunit.result.xml && touch build_passed
24 | - if [ -f build_passed ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
25 | - if [ -f build_passed ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
26 |
--------------------------------------------------------------------------------
/Grid/Column/AbstractGridColumn.php:
--------------------------------------------------------------------------------
1 | options[$key] = $value;
22 | }
23 |
24 | public function getOption($key)
25 | {
26 | if (isset($this->options[$key])) {
27 | return $this->options[$key];
28 | }
29 |
30 | return null;
31 | }
32 |
33 | public function getOrder()
34 | {
35 | return $this->order;
36 | }
37 |
38 | public function setOptions(array $options)
39 | {
40 | $this->options = $options;
41 | }
42 |
43 | public function getOptions()
44 | {
45 | return $this->options;
46 | }
47 |
48 | /**
49 | * @return string
50 | */
51 | public function getField()
52 | {
53 | return $this->field;
54 | }
55 |
56 | /**
57 | * @return string
58 | */
59 | public function getLabel()
60 | {
61 | return $this->label;
62 | }
63 |
64 | /**
65 | * @param string $field
66 | */
67 | public function setField($field)
68 | {
69 | $this->field = $field;
70 | }
71 |
72 | /**
73 | * @param string $label
74 | */
75 | public function setLabel($label)
76 | {
77 | $this->label = $label;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Resources/views/Grid/datatables.html.twig:
--------------------------------------------------------------------------------
1 | {% import _self as selfMacros %}
2 | {% macro attributes(attributes) %}
3 | {% for attb, value in attributes %}
4 | {{ attb }}="{{ value }}"
5 | {% endfor %}
6 | {% endmacro %}
7 |
8 |
9 |
10 |
11 | {% for column in columns %}
12 | |
13 | {{ column.getLabel() }}
14 | |
15 | {% endfor %}
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
42 |
--------------------------------------------------------------------------------
/Resources/views/layout.html.twig:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {% block head %}
5 |
6 | {% block title %}{% endblock %}
7 | {% block dtc_grid_stylesheets %}
8 | {% endblock %}
9 | {% block stylesheets %}
10 | {% for stylesheet in dtc_grid_theme_css %}
11 | {% if stylesheet.url is defined %}
12 |
16 | {% else %}
17 |
18 | {% endif %}
19 | {% endfor %}
20 | {% for stylesheet in dtc_grid_local_css %}
21 |
22 | {% endfor %}
23 | {% endblock %}
24 | {% block dtc_grid_javascripts %}
25 | {% endblock %}
26 | {% block javascripts %}
27 | {% for javascript in dtc_grid_theme_js %}
28 | {% if javascript.url is defined %}
29 |
33 | {% else %}
34 |
35 | {% endif %}
36 | {% endfor %}
37 | {% for javascript in dtc_grid_local_js %}
38 |
39 | {% endfor %}
40 | {% endblock javascripts %}
41 | {% endblock %}
42 |
43 |
44 |
45 | {% block grid %}
46 | {{ dtc_grid.render | raw }}
47 | {% endblock %}
48 |
49 |
53 |
54 |
--------------------------------------------------------------------------------
/Resources/public/js/datatables/action.js:
--------------------------------------------------------------------------------
1 | function dtc_grid_tableize(value) {
2 | var table = "| Column | Value | ";
3 | var stringifyValue = function (value) {
4 | if (value === null) {
5 | return 'null
';
6 | }
7 | if (typeof(value) === 'object') {
8 | return dtc_grid_tableize(value);
9 | }
10 | return $('').text(value).html();
11 | };
12 |
13 | for (var prop in value) {
14 | if (value.hasOwnProperty(prop)) {
15 | table += "| " + stringifyValue(prop) + " | " + stringifyValue(value[prop]) + " |
";
16 | }
17 | }
18 | table += "
";
19 | return table;
20 | }
21 |
22 | function dtc_grid_delete(context) {
23 | var $table = $(context).parents('table');
24 | var id = $table.attr('id');
25 | var route = $(context).attr('data-route');
26 | $(context).find('i').removeClass('dtc-grid-hidden');
27 | $table.find('button').attr('disabled','disabled');
28 | $.ajax({
29 | url: route,
30 | method: "POST"
31 | }).then(function () {
32 | $table.data('datatable').ajax.reload();
33 | })
34 | }
35 |
36 | function dtc_grid_refresh(context) {
37 | var id = $(context).attr('data-id');
38 | var $table = $('#' + id);
39 | if (!$table.get(0)) {
40 | return;
41 | }
42 | $(context).find('i').removeClass('dtc-grid-hidden');
43 | $(context).attr('disabled','disabled');
44 | $table.find('button').attr('disabled','disabled');
45 | $table.data('datatable').ajax.reload(function () {
46 | $(context).find('i').addClass('dtc-grid-hidden');
47 | $(context).attr('disabled',false);
48 | });
49 | }
50 |
51 | function dtc_grid_show(context) {
52 | var $table = $(context).parents('table');
53 | var id = $table.attr('id');
54 | var route = $(context).attr('data-route');
55 | var $modal = $('#' + 'modal-' + id);
56 | var identifier = $(context).attr('data-id');
57 | $modal.find('.modal-title').text('Show Id #' + identifier);
58 | $modal.modal('show');
59 | $modalBody = $modal.find('.modal-body');
60 | $modalBody.addClass('dtc-grid-spinner');
61 | $modalBody.html('
');
62 |
63 | $.ajax({
64 | url: route
65 | }).then(function (result) {
66 | console.log(result);
67 | $modalBody.removeClass('dtc-grid-spinner');
68 | $modalBody.html(dtc_grid_tableize(result));
69 | });
70 | }
--------------------------------------------------------------------------------
/Tests/Manager/GridSourceManagerTest.php:
--------------------------------------------------------------------------------
1 | setParameter('dtc_grid.custom_managers', []);
17 | $gridSourceManager = new GridSourceManager(new ColumnSource('/tmp', true));
18 | self::assertNotNull($gridSourceManager->all());
19 | self::assertInternalType('array', $gridSourceManager->all());
20 | self::assertEmpty($gridSourceManager->all());
21 | }
22 |
23 | public function testAdd()
24 | {
25 | $container = new Container();
26 | $container->setParameter('dtc_grid.custom_managers', []);
27 | $gridSourceManager = new GridSourceManager(new ColumnSource('/tmp', true));
28 | $gridSource = new TestGridSource();
29 | $gridSourceManager->add('test_grid_source', $gridSource);
30 | self::assertSame($gridSource, $gridSourceManager->get('test_grid_source'));
31 | try {
32 | $gridSourceManager->get('test_grirce');
33 | $this->fail('should not get a gridsource here');
34 | } catch (\Exception $exception) {
35 | }
36 | }
37 |
38 | public function testGetNegativeCase()
39 | {
40 | $container = new Container();
41 | $container->setParameter('dtc_grid.custom_managers', []);
42 | $gridSourceManager = new GridSourceManager(new ColumnSource('/tmp', true));
43 | $gridSource = new TestGridSource();
44 | try {
45 | $gridSourceManager->get('test_grirce');
46 | $this->fail('should not get a gridsource here');
47 | } catch (\Exception $exception) {
48 | }
49 | $gridSourceManager->add('test_grid_source', $gridSource);
50 | try {
51 | $gridSourceManager->get('test_grirce');
52 | $this->fail('should not get a gridsource here');
53 | } catch (\Exception $exception) {
54 | }
55 | try {
56 | $gridSourceManager->get('');
57 | $this->fail('should not get a gridsource here');
58 | } catch (\Exception $exception) {
59 | }
60 | try {
61 | $gridSourceManager->get(null);
62 | $this->fail('should not get a gridsource here');
63 | } catch (\Exception $exception) {
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Grid/Renderer/AbstractRenderer.php:
--------------------------------------------------------------------------------
1 | themeCss;
29 | $params['dtc_grid_theme_js'] = $this->themeJs;
30 | $params['dtc_grid_page_div_style'] = $this->pageDivStyle;
31 | $params['dtc_grid_local_css'] = [];
32 | $params['dtc_grid_local_js'] = [];
33 |
34 | return $params;
35 | }
36 |
37 | public function setOptions(array $values)
38 | {
39 | $this->options = $values;
40 | }
41 |
42 | public function setOption($key, $value)
43 | {
44 | $this->options[$key] = $value;
45 | }
46 |
47 | public function bind(GridSourceInterface $gridSource)
48 | {
49 | $this->gridSource = $gridSource;
50 | $this->afterBind();
51 |
52 | return $this;
53 | }
54 |
55 | public function getGridOptions()
56 | {
57 | return $this->options;
58 | }
59 |
60 | protected function afterBind()
61 | {
62 | }
63 |
64 | /**
65 | * @return mixed
66 | */
67 | public function getThemeCss()
68 | {
69 | return $this->themeCss;
70 | }
71 |
72 | /**
73 | * @param mixed $bootstrapCss
74 | */
75 | public function setThemeCss(array $themeCss)
76 | {
77 | $this->themeCss = $themeCss;
78 | }
79 |
80 | /**
81 | * @return mixed
82 | */
83 | public function getThemeJs()
84 | {
85 | return $this->themeJs;
86 | }
87 |
88 | /**
89 | * @param mixed $bootstrapJs
90 | */
91 | public function setThemeJs(array $themeJs)
92 | {
93 | $this->themeJs = $themeJs;
94 | }
95 |
96 | /**
97 | * @return mixed
98 | */
99 | public function getPageDivStyle()
100 | {
101 | return $this->pageDivStyle;
102 | }
103 |
104 | /**
105 | * @param mixed $pageDivStyle
106 | */
107 | public function setPageDivStyle($pageDivStyle)
108 | {
109 | $this->pageDivStyle = $pageDivStyle;
110 | }
111 |
112 | abstract public function render();
113 | }
114 |
--------------------------------------------------------------------------------
/Resources/doc/intro.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | ## Simple Grid
4 |
5 | If you want to simple grid with built in Grid Source, no customizations to grid columns, it's recommended to follow the instructions in the [README.md](/README.md) at the root of this project.
6 |
7 | ## Grid Generator
8 |
9 | For customizing is recommended to use the generator:
10 |
11 | bin/console dtc:grid:source:generate [--columns]
12 |
13 | * Use switch --columns if you want to customize columns, which will generate a custom columns twig file.
14 |
15 | You can use symfony's console to view registered grid sources:
16 |
17 | bin/console dtc:grid:source:list
18 |
19 | Otherwise see one of these:
20 |
21 | * [jQuery Datatables](/Resources/doc/DatatablesRenderer.md)
22 | * [jqGrid](/Resources/doc/jqGridRenderer.md)
23 | * [Table](/Resources/doc/TableRenderer.md)
24 |
25 | ## Custom Columns
26 |
27 | If you want to use the built in Grid Source with custom columns:
28 |
29 | * First setup the custom columns such as in: [GridColumns](/Resources/doc/GridColumns.md)
30 |
31 | Then setup your grid source as below:
32 |
33 | grid.source.user:
34 | class: Dtc\GridBundle\Grid\Source\EntityGridSource
35 | arguments: ['@doctrine.orm.default_entity_manager', AppBundle\Entity\User]
36 | tags: [{ name: dtc_grid.source }]
37 | calls: [[setColumns, ['@grid.source.user.columns']]]
38 | grid.source.user.columns:
39 | class: AppBundle\Grid\Columns\UserGridColumn
40 | arguments: ['@twig']
41 |
42 | ## Custom GridSource, Custom Columns
43 |
44 |
45 | If you want to override the existing Grid Source, with custom columns:
46 |
47 | You can extend:
48 |
49 | * Dtc\GridBundle\Grid\Source\DocumentGridSource
50 | * Dtc\GridBundle\Grid\Source\EntityGridSource
51 |
52 | YAML:
53 |
54 | grid.source.user:
55 | class: Path\To\Your\OverriddenGridSource
56 | arguments: ['@doctrine.orm.default_entity_manager', AppBundle\Entity\User]
57 | tags: [{ name: dtc_grid.source }]
58 | calls: [[setColumns, ['@grid.source.user.columns']]]
59 | grid.source.user.columns:
60 | class: AppBundle\Grid\Columns\UserGridColumn
61 | arguments: ['@twig']
62 |
63 | ## New GridSource
64 |
65 | If you want to create a new Grid Source:
66 |
67 | You can extend:
68 |
69 | * Dtc\GridBundle\Grid\Source\AbstractGridSource
70 |
71 | Or you can implement
72 |
73 | * Dtc\GridBundle\Grid\Source\GridSourceInterface
74 |
75 | YAML:
76 |
77 | grid.source.user:
78 | class: Path\To\Your\NewGridSource
79 | arguments: ['@your_services', 'etc']
80 | tags: [{ name: dtc_grid.source }]
81 | calls: [[autoDiscoverColumns]]
82 |
--------------------------------------------------------------------------------
/Resources/config/grid.yml:
--------------------------------------------------------------------------------
1 | services:
2 | dtc_grid.renderer.factory:
3 | public: true
4 | class: Dtc\GridBundle\Grid\Renderer\RendererFactory
5 | arguments:
6 | - "@router"
7 | - "@translator"
8 | -
9 | theme.css: '%dtc_grid.theme.css%'
10 | theme.js: '%dtc_grid.theme.js%'
11 | page_div_style: '%dtc_grid.page_div_style%'
12 | jquery: '%dtc_grid.jquery%'
13 | purl: '%dtc_grid.purl%'
14 | table.options: '%dtc_grid.table_options%'
15 | jq_grid.css: '%dtc_grid.jq_grid.css%'
16 | jq_grid.js: '%dtc_grid.jq_grid.js%'
17 | jq_grid.local.css: '%dtc_grid.jq_grid.local.css%'
18 | jq_grid.local.js: '%dtc_grid.jq_grid.local.js%'
19 | jq_grid.options: '%dtc_grid.jq_grid.options%'
20 | datatables.css: '%dtc_grid.datatables.css%'
21 | datatables.js: '%dtc_grid.datatables.js%'
22 | datatables.local.css: '%dtc_grid.datatables.local.css%'
23 | datatables.local.js: '%dtc_grid.datatables.local.js%'
24 | datatables.class: '%dtc_grid.datatables.class%'
25 | datatables.options: '%dtc_grid.datatables.options%'
26 | dtc_grid.command.source_list:
27 | public: true
28 | class: Dtc\GridBundle\Command\SourceListCommand
29 | calls:
30 | - [ "setGridSourceManager", ['@dtc_grid.manager.source'] ]
31 | tags:
32 | - { name: console.command }
33 | dtc_grid.command.generate_grid_source:
34 | public: true
35 | class: Dtc\GridBundle\Command\GenerateGridSourceCommand
36 | calls:
37 | - [ "setRegistry", ['@?doctrine'] ]
38 | - [ "setMongoDBRegistry", ['@?doctrine_mongodb'] ]
39 | - [ "setEntityManager", ['@?doctrine.orm.default_entity_manager'] ]
40 | - [ "setDocumentManager", ['@?doctrine_mongodb.odm.default_document_manager'] ]
41 | tags:
42 | - { name: console.command }
43 | dtc_grid.column.source:
44 | public: true
45 | class: Dtc\GridBundle\Grid\Source\ColumnSource
46 | arguments:
47 | - "%kernel.cache_dir%"
48 | - "%kernel.debug%"
49 | dtc_grid.manager.source:
50 | public: true
51 | class: Dtc\GridBundle\Manager\GridSourceManager
52 | arguments:
53 | - "@dtc_grid.column.source"
54 | calls:
55 | - [ 'setReader', ['@?annotation_reader']]
56 | - [ 'setReflectionAllowedEntities', ['%dtc_grid.reflection.allowed_entities%']]
57 | dtc_grid.twig.extension:
58 | class: Dtc\GridBundle\Twig\Extension\TwigExtension
59 | tags:
60 | - { name: twig.extension }
61 | dtc_grid.command.source.list:
62 | class: Dtc\GridBundle\Command\SourceListCommand
63 | tags:
64 | - { name: 'console.command' }
65 | dtc_grid.command.source.generate:
66 | class: Dtc\GridBundle\Command\GenerateGridSourceCommand
67 | tags:
68 | - { name: 'console.command' }
69 | dtc_grid.controller.grid:
70 | public: true
71 | class: Dtc\GridBundle\Controller\GridController
72 | arguments:
73 | - "@service_container"
74 |
--------------------------------------------------------------------------------
/Resources/doc/TableRenderer.md:
--------------------------------------------------------------------------------
1 | # Html Grid Renderer
2 |
3 | ## 1. Create a GridSource service
4 |
5 | XML:
6 |
7 |
8 | Odl\ShadowBundle\Documents\Character
9 | grid.source.character
10 |
11 |
12 |
13 | YAML:
14 | grid.source.user:
15 | class: Dtc\GridBundle\Grid\Source\DocumentGridSource
16 | arguments: ['@doctrine_mongodb.odm.default_document_manager', AppBundle\Document\User]
17 | tags: [{ name: dtc_grid.source }]
18 | calls: [[autoDiscoverColumns]]
19 |
20 | * For ORMs, use
21 | * Dtc\GridBundle\Grid\Source\EntityGridSource
22 | * @doctrine.orm.default_entity_manager
23 |
24 | ## For your controller:
25 |
26 | /**
27 | * @Template
28 | * @Route("/users_html", name="dtc_grid_users_html")
29 | */
30 | public function usersHtmlAction(Request $request) {
31 | $renderer = $this->get('dtc_grid.renderer.table');
32 | $gridSource = $this->get('grid.source.user');
33 | $columns = $gridSource->getColumns();
34 | $renderer->bind($gridSource);
35 |
36 | return array('dtc_grid' => $renderer);
37 | }
38 |
39 |
40 | ## For your template
41 |
42 | Resources/views/your_controller/usersHtml.html.twig
43 |
44 |
45 |
46 |
47 |
48 | {% block stylesheets %}
49 | {% for stylesheet in dtc_grid_theme_css %}
50 | {% if stylesheet.url is defined %}
51 |
55 | {% else %}
56 |
57 | {% endif %}
58 | {% endfor %}
59 | {% for stylesheet in dtc_grid_local_css %}
60 |
61 | {% endfor %}
62 | {% endblock %}
63 | {% block javascripts %}
64 | {% for javascript in dtc_grid_theme_js %}
65 | {% if javascript.url is defined %}
66 |
70 | {% else %}
71 |
72 | {% endif %}
73 | {% endfor %}
74 | {% for javascript in dtc_grid_local_js %}
75 |
76 | {% endfor %}
77 | {% endblock javascripts %}
78 |
79 |
80 | {{ dtc_grid.render | raw }}
81 |
82 |
--------------------------------------------------------------------------------
/Grid/Column/ActionGridColumn.php:
--------------------------------------------------------------------------------
1 | ';
11 |
12 | protected $actions;
13 | protected $idField;
14 |
15 | /** @var RouterInterface */
16 | protected $router;
17 | protected $gridSourceId;
18 |
19 | public function __construct($field, array $actions, $idField = 'id')
20 | {
21 | $this->actions = $actions;
22 | $this->idField = $idField;
23 | $this->label = 'Actions';
24 | $this->field = $field;
25 | }
26 |
27 | public function format($object, GridSourceInterface $gridsource)
28 | {
29 | $method = 'get'.ucfirst($this->idField);
30 | $id = $object->$method();
31 | $idHtml = htmlspecialchars($id);
32 | $content = '';
33 | foreach ($this->actions as $action => $options) {
34 | $label = $options['label'];
35 | if ($content) {
36 | $content .= ' ';
37 | }
38 | $route = isset($options['route']) ? $options['route'] : '';
39 | switch ($options['action']) {
40 | case 'show':
41 | if (!$route) {
42 | $route = 'dtc_grid_show';
43 | }
44 | $uri = $this->router->generate($route, ['identifier' => $id, 'id' => $this->gridSourceId]);
45 | $uri = htmlspecialchars($uri);
46 | $content .= "";
48 | break;
49 | case 'delete':
50 | if (!$route) {
51 | $route = 'dtc_grid_delete';
52 | }
53 | $uri = $this->router->generate($route, ['identifier' => $id, 'id' => $this->gridSourceId]);
54 | $uri = htmlspecialchars($uri);
55 | $content .= "