Mercure Integration
Use Mercure when table data can change outside the current browser session and you want automatic refresh.
MercureConfig can now be configured manually through DataTable::mercure(...) or auto-resolved from #[AsDataTable(..., mercure: true)].
What The Integration Does
When mercure is configured on a table:
- Backend options include a
mercureobject (hubUrl,topics, optionalwithCredentials, optionaldebounceMs). - The Stimulus controller opens an
EventSourceto the hub with?topic=.... - On each message, the controller emits a
datatables:mercure:messageevent and triggerstable.ajax.reload(null, false). - The SSE connection is closed automatically on controller
disconnect().
Minimal Setup
#[AsDataTable(Book::class, mercure: true)]
final class BookDataTable extends AbstractDataTable
{
}
When auto-resolution is enabled:
- the bundle reads the default Symfony Mercure hub URL
- explicit API Platform
mercure.topicsare reused when available - otherwise the bundle falls back to an item IRI template (for example
/api/books/{id}) - if no API Platform item metadata is available, it falls back to
/datatables/books/{id}
Advanced Setup
$dataTable->mercure(
hubUrl: '/.well-known/mercure',
topics: ['admin/books', 'admin/authors'],
withCredentials: true,
debounceMs: 300,
);
Notes:
withCredentialsenables cookie/auth forwarding in the SSE request.debounceMsis applied client-side before reload (500msby default).topicsaccepts one or many topics.
Publishing Updates
If symfony/mercure is available, the bundle registers MercureUpdatePublisher and injects it into the Ajax edit controller.
When boolean inline edit is called with topics, the controller publishes:
{
"type": "edit",
"id": "...",
"field": "..."
}
You can also publish manually with MercureUpdatePublisher::publish() or publishForDataTable().
Operational Notes
- Mercure refresh uses
ajax.reload(...): tables configured only with staticdatawill not auto-refresh from SSE. - No Mercure config means no SSE subscription (dynamic import is skipped).
- If the table receives many events, tune
debounceMsto protect backend load. private: truefrom API Platform metadata is not mapped automatically towithCredentials.