This bundle provides the Datatables format to the API Platform.
composer require m2mtech/api-platform-datatables-format
If you are not using Flex enable the bundle:
// config/bundles.php
return [
// ...
M2MTech\ApiPlatformDatatablesFormat\M2MTechApiPlatformDatatablesFormatBundle::class => ['all' => true],
];
Enable the datatables format:
# config/packages/api_platform.yaml
api_platform:
formats:
datatables: [ 'application/vnd.datatables+json' ]
The package rewrites the query parameters start
and length
from datatables to page
and itemsPerPage
or whatever you have set as page_parameter_name
and items_per_page_parameter_name
for the API Platform.
e.g.:
- /api/offers?draw=1&start=0&length=10
+ /api/offers?draw=1&page=1&itemsPerPage=10
Pagination is enabled by default in the API Platform.
The package rewrites the query parameters columns
and order
from datatables to order
or whatever you have set as order_parameter_name
for the API Platform.
e.g.:
- /api/offers?draw=2&columns[0][data]=name&columns[1][data]=price&order[0][column]=1&order[0][dir]=desc
+ /api/offers?draw=2&order[email]=desc
You need to enable sorting for the API Platform.
e.g. in your entity definition:
#[ApiFilter(OrderFilter::class, properties: ['name', 'price'])]
The package rewrites the query parameters columns
and search
from datatables to or
for the Filter logic for API Platform.
e.g.:
- /api/offers?draw=3&columns[0][data]=name&columns[1][data]=description&search[value]=shirt
+ /api/offers?draw=2&or[name]=shirt&or[desciption]=shirt
You need to install Filter logic for API Platform, an equivalent bundle or your own filter for this functionality, e.g.:
composer require metaclass-nl/filter-bundle "dev-master"
You need also to enable the search filter for the API Platform.
e.g. in your entity definition:
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'description' => 'partial'])]
#[ApiFilter(FilterLogic::class)]
Including the data, the output contains recordsTotal
and recordsFiltered
(which are always the same) as well as the draw
parameter from the query.
This package has been developed for php 7.4 with compatibility tested for php 7.2 to 8.1.
composer test
Please see CHANGELOG for more information about recent changes.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.