Download the PHP package waldo/datatable-bundle without Composer
On this page you can find all versions of the php package waldo/datatable-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download waldo/datatable-bundle
More information about waldo/datatable-bundle
Files in waldo/datatable-bundle
Package datatable-bundle
Short Description Symfony2 Ajax Datagrid Bundle for doctrine2 entities
License MIT
Homepage https://github.com/waldo2188/DatatableBundle
Informations about the package datatable-bundle
DatatableBundle
Fork of AliHichem/DatatableBundle, this bundle will add some great features and evolve in a different way than it source.
Warning: The jQuery Datatable plugin has evolved (version 1.10) with a all new API and option.
You MUST use the version 2 of DatatableBundle with the jQuery Datatable plugin version lower than 1.10.
You MUST use the version 3 of DatatableBundle with the jQuery Datatable plugin version equal or greater than 1.10.
The Datatable bundle for symfony2 allow for easily integration of the jQuery Datatable plugin with the doctrine2 entities. This bundle provides a way to make a projection of a doctrine2 entity to a powerful jquery datagrid. It mainly includes:
- datatable service container: to manage the datatable as a service.
- twig extension: for view integration.
- dynamic pager handler : no need to set your pager.
- support doctrine2 association.
- support of Doctrine Query Builder.
- support of doctrine subquery.
- support of column search.
- support of custom twig/phpClosure renderers.
Summary
- Installation
- Download DatatableBundle using Composer
- Enable the Bundle
- Configure the Bundle
- How to use DatatableBundle ?
- Rendering inside Twig
- Advanced Use of DatatableBundle
- Use of search filters
- Activate search globally
- Set search fields
- Multiple actions, how to had checkbox for each row ?
- Custom renderer for cells
- Datatable Callbacks options
- Translation
- Doctrine Query Builder
- Multiple datatable in the same view
- Use specific jQuery Datatable options
- Launch the test suite
Installation
Installation is a quick (I promise!) 3 step process:
- Download DatatableBundle using Composer
- Enable the Bundle
- Configure the Bundle
Download DatatableBundle using Composer
Using Composer
Install with this command : composer require waldo/datatable-bundle
Generate the assets symlinks :
Enable the Bundle
Add the bundle to the AppKernel.php
Configure the Bundle
In this section you can put the global config that you want to set for all the instance of DataTable in your project.
To keep it to default
The js
config will be applied to DataTable exactly like you do with $().datatable({ your config });
in a javascript part.
Note: all your js config have to be string typed, make sure to use (") as delimiters.
Config sample
How to use DatatableBundle ?
Assuming for example that you need a grid in your "index" action, create in your controller method as below :
Warning alias as
is case-sensitive, always write it in lower case
Rendering inside Twig
You have the choice, you can render the HTML table part and Javascript part in just one time with the Twig function datatable
,
like below.
Or, render each part separatly.
datatable_html
is the Twig function for the HTML part.
datatable_js
is the Twig function for the Javascript part.
Advanced Use of DatatableBundle
Advanced php config
Assuming the example above, you can add your joins and where statements.
Use of search filter
- Activate search globally
- Set search fields
Activate search globally
The searching functionality that is very useful for quickly search through the information from the database. This bundle provide two way of searching, who can be used together : global search and individual column search.
By default the filtering functionality is disabled, to get it working you just need to activate it from your configuration method like this :
Set search fields
You can set fields where you want to enable your search. Let say you want search to be active only for "field 1" and "field3 ", you just need to activate search for the approriate column key and your datatable config should be :
Multiple actions, how to had checkbox for each row ?
Sometimes, it's good to be able to do the same action on multiple records like deleting, activating, moving ... Well this is very easy to add to your datatable: all what you need is to declare your multiple action as follow.
Then all what you have to do is to add the necessary logic in your "multiple_delete_route" (or whatever your route is for). In that action, you can get the selected ids by :
Custom renderer for cells
Twig renderers
To set your own column structure, you can use a custom twig renderer as below : In this example you can find how to set the use of the default twig renderer for action fields which you can override as your own needs.
In a twig renderer you can have access the the field value using dt_item
variable,
or access the entire entity object using dt_obj
variable.
NOTE: be careful of Doctrine's LAZY LOADING when using dt_obj !
PHP Closures
Assuming the example above, you can set your custom fields renderer using PHP Closures.
DataTable Callbacks options
If you need to put some Javascript Callbacks like drawCallback
, you can
do it localy with the Datatable js
option. See the two examples below:
You can also define a Callback globally by setting it up in the config.yml
like below :
Translation
You can set your own translated labels by adding in your translation catalog entries as define in Resources/translations/messages.en.yml
You can also get the translated labels from official DataTable translation repository, by configuring the bundle like below :
This bundle includes nine translation catalogs: Arabic, Chinese, Dutch, English, Spanish, French, Italian, Polish, Russian and Turkish To get more translated entries, you can follow the official DataTable translation
Doctrine Query Builder
To use your own query object to supply to the datatable object, you can perform this action using your own "Doctrine Query object": DatatableBundle allow to manipulate the query object provider which is now a Doctrine Query Builder object, you can use it to update the query in all its components except of course in the selected field part.
This is a classic config before using the Doctrine Query Builder:
This is a config that uses a Doctrine Query object a query builder :
Multiple DataTable in the same view
To declare multiple DataTables in the same view, you have to set the datatable identifier in you controller with setDatatableId
:
Each of your DataTable config methods ( datatable() , datatable_1() .. datatable_n() ) needs to set the same identifier used in your view:
In the controller
In the view
Use specific jQuery DataTable options
Some time we need to apply some specific options to a grid, like a specific width for the second column. DataTable comes with a lot a feature that you can always use, even with this bundle.
In the code below, we use the columnDefs
option to fix the width of the second column.
You really can play with all the DataTable's options.