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 paramsAPI 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, serverSide is 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`
PurposeAuto-configure Ajax options for API Platform resources
Applied toTables with resolvable API Platform collection metadata

Conditions:

Condition Required
No explicit `ajax` optionYes
No explicit `data` optionYes
`#[AsDataTable(...)]` existsYes
A collection URL can be resolved from API Platform metadataYes

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 ajax or data is already set.
  • Forgetting that non-readable resource properties are skipped in auto-detection.