secamedia / datatables-form-bundle
Provides Form Types and Entities representing the DataTables AJAX Request.
Installs: 516
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.5.9
- symfony/form: ^2.8|^3.0|^4.0|^5.0
This package is auto-updated.
Last update: 2024-04-11 18:43:02 UTC
README
This is a Symfony Bundle to represent the DataTables Ajax Request Data into an entity via form types.
Installation via Composer
Install it via composer as a dependency:
$ php composer.phar require secamedia/datatables-form-bundle
Activation
Register the bundle in the kernel to activate the bundle.
public function registerBundles() { $bundles = [ ... new Sm\DatatablesFormBundle\SmDatatablesFormBundle(), ... ]; }
How to use with DataTables ajax request
To recognize the request data you have to move the datatables data into
the key datatables
:
$('table').DataTable({ 'ajax': { 'url': '/ajax-request.php', 'data': function (data) { // Move DataTables data into own key for (var d in data) { if (!data.hasOwnProperty(d)) { continue; } data['datatables[' + d + ']'] = data[d]; delete data[d]; } }, 'type': 'POST' } });
In your controller you can then create a form and set the entity to retrieve the data as an object:
use Sm\DatatablesFormBundle\Entity\DataTablesForm; use Sm\DatatablesFormBundle\Form\Type\DataTablesFormType; ... public function someAction(Request $request) { $data = new DataTablesForm(); $form = $this->createForm(DataTablesFormType::class, $data); $form->handleRequest($request); // use $data } ...