@@ -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
148151Global 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
175178translation_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\D ataTablesBundle\A dapter\D octrine\O RMAdapter;
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
0 commit comments