Skip to content

Commit 38e29ca

Browse files
committed
Finish splitting out docs from README
1 parent 2734bdf commit 38e29ca

File tree

4 files changed

+94
-90
lines changed

4 files changed

+94
-90
lines changed

README.md

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,6 @@ Elastica, Doctrine DBAL and MongoDB out of the box as well.
2020

2121
[Visit the documentation with extensive code samples](https://omines.github.io/datatables-bundle/).
2222

23-
The documentation below is pending move to the external site.
24-
25-
#### Making a separate datatable type
26-
27-
Having the table configuration in your controller is convenient, but not practical for reusable or
28-
extensible tables, or highly customized tables.
29-
30-
In the example above we could also create a class `DataTable\Type\PresidentsTableType` in our app bundle,
31-
and make it implement `Omines\DataTablesBundle\DataTableTypeInterface`. We can then use:
32-
33-
```php
34-
$table = $this->createDataTableFromType(PresidentsTableType::class)
35-
->handleRequest($request);
36-
```
37-
This ensures your controllers stay lean and short, and only delegate tasks. Of course you can modify
38-
the base type to fit the controller's specific needs before calling `handleRequest`.
39-
40-
If you need dependencies injected just register `PresidentsTableType` as a service in the container, and
41-
tag it with `datatables.type`. Or just use `autoconfigure:true` as is recommended Symfony practice.
42-
43-
### Doctrine integration
44-
45-
If you have installed `doctrine/doctrine-bundle` several convenient wrappers are available to easily make
46-
highly flexible tables.
47-
48-
#### Doctrine ORM
49-
50-
If you have installed `doctrine/orm` you can use the provided `ORMAdapter`. Assume a simple `Employee` table
51-
with some basic fields and a ManyToOne relationship to `Company`:
52-
```php
53-
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
54-
...
55-
56-
$table = $this->createDataTable()
57-
->add('firstName', TextColumn::class)
58-
->add('lastName', TextColumn::class)
59-
->add('company', TextColumn::class, ['field' => 'company.name'])
60-
->createAdapter(ORMAdapter::class, [
61-
'entity' => Employee::class,
62-
])
63-
```
64-
That's all actually! The table will even be searchable.
65-
66-
Underneath a lot of "magic" is happening in this most simple of examples. The first 2 columns automatically
67-
have their `field` option defaulted to the "root entity" of the adapter, with the field identical to their
68-
name. The adapter itself did not get a query, and as such injected the `AutomaticQueryBuilder` supplied by
69-
this bundle, which scans the metadata and automatically joins and selects the right data based on the fields.
70-
Secondly, since no criteria processors were supplied a default `SearchCriteriaProvider` was injected to
71-
apply global search to all mapped fields.
72-
73-
Of course, all of this is just convenient default. For more complex scenarios you can supply your own query
74-
builders and criteria providers, and even chain them together to easily implement multiple slightly different
75-
tables in your site.
76-
77-
### Advanced
78-
More advanced examples will follow.
79-
8023
## Contributing
8124

8225
Please see [CONTRIBUTING.md](https://github.com/omines/datatables-bundle/blob/master/CONTRIBUTING.md) for details.

docs/source/index.html.md

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,33 @@ datatables:
119119
# Load i18n data from DataTables CDN or locally
120120
language_from_cdn: true
121121

122-
# Persist request state automatically
123-
request_state: true
124-
125-
# Default class attribute to apply to the root table elements
126-
class_name: ~
127-
128122
# Default HTTP method to be used for callbacks
129123
method: POST # One of "GET"; "POST"
130124

131-
# Default translation domain to be used
132-
translation_domain: messages
133-
134-
# If and where to enable the DataTables Filter module
135-
column_filter: null # One of "thead"; "tfoot"; "both"; null
136-
137125
# Default options to load into DataTables
138126
options:
139-
# Default table options
127+
option: value
140128

141-
# Default template to be used for DataTables HTML
142-
template: ~
129+
# Where to persist the current table state automatically
130+
persist_state: fragment # One of "query"; "fragment"; "local"; "session"
143131

144-
# Default service used to render templates
132+
# Default service used to render templates, built-in TwigRenderer uses global Twig environment
145133
renderer: Omines\DataTablesBundle\Twig\TwigRenderer
134+
135+
# Default template to be used for DataTables HTML
136+
template: '@DataTables/datatable_html.html.twig'
137+
138+
# Default parameters to be passed to the template
139+
template_parameters:
140+
141+
# Default class attribute to apply to the root table elements
142+
className: 'table table-bordered'
143+
144+
# If and where to enable the DataTables Filter module
145+
columnFilter: null # One of "thead"; "tfoot"; "both"; null
146+
147+
# Default translation domain to be used
148+
translation_domain: messages
146149
```
147150
148151
Global configuration of the bundle is done in your config file. The default configuration is shown here,
@@ -175,3 +178,59 @@ language_from_cdn | bool | true | Either loads DataTables' own translations from
175178
translation_domain | string | messages | Default translation domain used in the table structure.
176179

177180
## Options
181+
182+
# Core concepts
183+
184+
## DataTable types
185+
186+
Having the table configuration in your controller is convenient, but not practical for reusable or
187+
extensible tables, or highly customized tables.
188+
189+
In the example above we could also create a class `DataTable\Type\PresidentsTableType` in our app bundle,
190+
and make it implement `Omines\DataTablesBundle\DataTableTypeInterface`. We can then use:
191+
192+
```php?start_inline=1
193+
$table = $this->createDataTableFromType(PresidentsTableType::class)
194+
->handleRequest($request);
195+
```
196+
This ensures your controllers stay lean and short, and only delegate tasks. Of course you can modify
197+
the base type to fit the controller's specific needs before calling `handleRequest`.
198+
199+
If you need dependencies injected just register `PresidentsTableType` as a service in the container, and
200+
tag it with `datatables.type`. Or just use `autoconfigure:true` as is recommended Symfony practice.
201+
202+
# Adapters
203+
204+
Ready-made adapters are supplied for easy integration with various data sources.
205+
206+
## Doctrine ORM
207+
208+
```php?start_inline=1
209+
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
210+
211+
$table = $this->createDataTable()
212+
->add('firstName', TextColumn::class)
213+
->add('lastName', TextColumn::class)
214+
->add('company', TextColumn::class, ['field' => 'company.name'])
215+
->createAdapter(ORMAdapter::class, [
216+
'entity' => Employee::class,
217+
]);
218+
```
219+
If you have installed `doctrine/orm` and `doctrine/doctrine-bundle` you can use the provided `ORMAdapter`.
220+
Assume a simple `Employee` table with some basic fields and a ManyToOne relationship to `Company` for
221+
these examples.
222+
223+
Underneath a lot of "magic" is happening in this most simple of examples. The first 2 columns automatically
224+
have their `field` option defaulted to the "root entity" of the adapter, with the field identical to their
225+
name. The adapter itself did not get a query, and as such injected the `AutomaticQueryBuilder` supplied by
226+
this bundle, which scans the metadata and automatically joins and selects the right data based on the fields.
227+
Secondly, since no criteria processors were supplied a default `SearchCriteriaProvider` was injected to
228+
apply global search to all mapped fields.
229+
230+
Of course, all of this is just convenient default. For more complex scenarios you can supply your own query
231+
builders and criteria providers, and even chain them together to easily implement multiple slightly different
232+
tables in your site.
233+
234+
## Arrays
235+
236+
## Implementing your own

src/Twig/DataTablesExtension.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,28 @@ private function getLanguageSettings(DataTable $dataTable)
108108
if ($dataTable->isLanguageFromCDN() && array_key_exists($locale, $this->languageCDNFile)) {
109109
return ['url' => "//cdn.datatables.net/plug-ins/1.10.15/i18n/{$this->languageCDNFile[$locale]}"];
110110
} else {
111+
$domain = $dataTable->getTranslationDomain();
111112
return [
112-
'processing' => $this->translator->trans('datatable.datatable.processing'),
113-
'search' => $this->translator->trans('datatable.datatable.search'),
114-
'lengthMenu' => $this->translator->trans('datatable.datatable.lengthMenu'),
115-
'info' => $this->translator->trans('datatable.datatable.info'),
116-
'infoEmpty' => $this->translator->trans('datatable.datatable.infoEmpty'),
117-
'infoFiltered' => $this->translator->trans('datatable.datatable.infoFiltered'),
118-
'infoPostFix' => $this->translator->trans('datatable.datatable.infoPostFix'),
119-
'loadingRecords' => $this->translator->trans('datatable.datatable.loadingRecords'),
120-
'zeroRecords' => $this->translator->trans('datatable.datatable.zeroRecords'),
121-
'emptyTable' => $this->translator->trans('datatable.datatable.emptyTable'),
122-
'searchPlaceholder' => $this->translator->trans('datatable.datatable.searchPlaceholder'),
113+
'processing' => $this->translator->trans('datatable.datatable.processing', $domain),
114+
'search' => $this->translator->trans('datatable.datatable.search', $domain),
115+
'lengthMenu' => $this->translator->trans('datatable.datatable.lengthMenu', $domain),
116+
'info' => $this->translator->trans('datatable.datatable.info', $domain),
117+
'infoEmpty' => $this->translator->trans('datatable.datatable.infoEmpty', $domain),
118+
'infoFiltered' => $this->translator->trans('datatable.datatable.infoFiltered', $domain),
119+
'infoPostFix' => $this->translator->trans('datatable.datatable.infoPostFix', $domain),
120+
'loadingRecords' => $this->translator->trans('datatable.datatable.loadingRecords', $domain),
121+
'zeroRecords' => $this->translator->trans('datatable.datatable.zeroRecords', $domain),
122+
'emptyTable' => $this->translator->trans('datatable.datatable.emptyTable', $domain),
123+
'searchPlaceholder' => $this->translator->trans('datatable.datatable.searchPlaceholder', $domain),
123124
'paginate' => [
124-
'first' => $this->translator->trans('datatable.datatable.paginate.first'),
125-
'previous' => $this->translator->trans('datatable.datatable.paginate.previous'),
126-
'next' => $this->translator->trans('datatable.datatable.paginate.next'),
127-
'last' => $this->translator->trans('datatable.datatable.paginate.last'),
125+
'first' => $this->translator->trans('datatable.datatable.paginate.first', $domain),
126+
'previous' => $this->translator->trans('datatable.datatable.paginate.previous', $domain),
127+
'next' => $this->translator->trans('datatable.datatable.paginate.next', $domain),
128+
'last' => $this->translator->trans('datatable.datatable.paginate.last', $domain),
128129
],
129130
'aria' => [
130-
'sortAscending' => $this->translator->trans('datatable.datatable.aria.sortAscending'),
131-
'sortDescending' => $this->translator->trans('datatable.datatable.aria.sortDescending'),
131+
'sortAscending' => $this->translator->trans('datatable.datatable.aria.sortAscending', $domain),
132+
'sortDescending' => $this->translator->trans('datatable.datatable.aria.sortDescending', $domain),
132133
],
133134
];
134135
}

src/Twig/TwigRenderer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(Twig_Environment $twig = null)
4444
public function renderDataTable(DataTable $dataTable, string $template, array $parameters): string
4545
{
4646
$parameters['datatable'] = $dataTable;
47+
4748
return $this->twig->render($template, $parameters);
4849
}
4950
}

0 commit comments

Comments
 (0)