API Platform Integration
UX DataTables supports two integration paths with API Platform.
1) Ajax Adapter Mode (DataTable::apiPlatform())
Use this mode when DataTables runs in server-side mode and your endpoint is an API Platform collection.
use Pentiminax\UX\DataTables\Model\DataTable;
$dataTable = new DataTable('books');
$dataTable
->ajax('/api/books')
->serverSide(true)
->apiPlatform(true);
The frontend adapter converts:
| Input | Output |
|---|---|
| DataTables query params | API Platform params (`page`, `itemsPerPage`, `order[field]`, filters) |
| Hydra response (`hydra:member`, `hydra:totalItems`) | DataTables response shape |
Notes:
- Date formatting is handled by the backend payload. The adapter does not reformat date values on the client.
- When API Platform adapter mode is enabled,
serverSideis enforced so sorting and filtering stay consistent with API queries.
2) AbstractDataTable Auto Ajax Wiring
When rendering an AbstractDataTable, calling getDataTable() auto-configures Ajax for API resources when possible.
| Aspect | Value |
|---|---|
| Trigger | `getDataTable()` / Twig rendering of `AbstractDataTable` |
| Purpose | Auto-configure Ajax options for API Platform resources |
| Applied to | Tables with resolvable API Platform collection metadata |
Conditions:
| Condition | Required |
|---|---|
| No explicit `ajax` option | Yes |
| No explicit `data` option | Yes |
| `#[AsDataTable(...)]` exists | Yes |
| A collection URL can be resolved from API Platform metadata | Yes |
If #[AsDataTable(..., mercure: true)] is also enabled and a Mercure hub is configured, the same preparation pass can auto-attach Mercure topics for live reload.
Example resolved output:
| Option | Value |
|---|---|
| `ajax.url` | `/api/books` |
| `ajax.type` | `GET` |
| `apiPlatform` | `true` |
Column Auto Detection
If API Platform metadata is available, columns can be auto-detected from readable properties.
#[AsDataTable] supports serialization groups:
#[AsDataTable(Book::class, serializationGroups: ['book:list'])]
Frequent Pitfalls
- Enabling adapter mode without an Ajax endpoint.
- Expecting auto Ajax wiring when
ajaxordatais already set. - Forgetting that non-readable resource properties are skipped in auto-detection.