Download the PHP package survos/api-grid-bundle without Composer
On this page you can find all versions of the php package survos/api-grid-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download survos/api-grid-bundle
More information about survos/api-grid-bundle
Files in survos/api-grid-bundle
Package api-grid-bundle
Short Description incorporate DatatablesNet, using twig and stimulus, twig_component requires ^2.2
License MIT
Informations about the package api-grid-bundle
Survos API Grid Bundle
A Symfony bundle that renders a server-driven DataTables 3.0 grid from an API Platform collection endpoint, using Twig Components and a Stimulus controller.
Beta notice — This bundle ships with DataTables 3.0 beta packages (
datatables.net-bs5 3.0.0-beta.2and related extensions). Beta users get active upstream support from the DataTables team, which means faster bug fixes and direct access to new features.
Key features:
- Zero-config column inference from PHP attributes (
#[Field],#[ApiFilter]) - ColumnControl — per-column sort / search / facet dropdowns (default)
- SearchBuilder — modal query builder with AND/OR logic
- Responsive, multi-row select, bulk actions, offcanvas detail panel
- Custom cell rendering via inline Twig blocks (server-side Twig, zero JS templating required)
- Bootstrap 5 / Tabler-compatible out of the box
Requirements
- PHP 8.4+
- Symfony 7.4 or 8.0
- API Platform 4.1+
survos/field-bundle(optional but recommended for attribute-driven config)
Install
Assets are registered via Symfony UX. Add the Stimulus controller to your importmap.php:
Quick Start
This four-step setup gives you a working sortable, searchable, filterable grid.
1. Annotate the entity
Add API Platform filters to the entity. The bundle reads these annotations to infer which columns are sortable, searchable, and filterable without any explicit column configuration.
If you use survos/field-bundle, annotate properties instead — see Field-Bundle Integration.
2. Compute the collection URL in the controller
Resolve the URL server-side so the template gets a plain string. This keeps the Twig template simple and makes debugging straightforward (the URL is visible in the browser network tab).
3. Render the grid in Twig
The col() Twig function is provided by the bundle. Each call returns a Column object. Arguments map directly to Column properties — see Column Reference.
4. Enable client-side pagination
DataTables uses limit/offset (not page). The bundle ships a SlicePaginationExtension that handles this, but API Platform must allow client control:
Entity Setup
Sorting
Global search
The Stimulus controller sends the search box value as individual field parameters (one per searchable column). For a single unified ?search= parameter, use MultiFieldSearchFilter:
Facet filters (ColumnControl / SearchBuilder)
Columns marked browsable: true use this filter. In ColumnControl mode they render as searchable dropdowns; in SearchBuilder mode they appear as criteria fields.
Field-Bundle Integration
If survos/field-bundle is installed, add #[Field] to entity properties instead of #[ApiFilter]. The bundle reads FieldDescriptor objects from FieldReader and uses them as the authoritative source for column settings.
#[Field] drives: searchable, sortable, browsable (via filterable + widget), visible, width, widget.
Explicit col() arguments always override #[Field] defaults. See Field-Bundle Integration for the full layering rules.
Twig Component Reference
Column Reference
Columns can also be passed as plain arrays (backward compatible):
Widget Modes
The grid supports two filter UI modes. See docs/widgets.md for full documentation.
ColumnControl (recommended)
Per-column dropdowns embedded directly in the column headers. Ideal when the page already has a sidebar (e.g. EasyAdmin, Tabler).
Browsable columns (browsable: true) render as searchable dropdown lists.
Columns with widget: 'range' render as min/max number inputs.
SearchBuilder
A modal query builder with AND/OR logic. Browsable columns appear as criteria fields.
Custom Cell Rendering
Pass :caller="_self" and add <twig:block name="fieldName"> blocks to override rendering for specific columns. The variable row contains the full deserialized API response row.
Blocks are compiled server-side by the js-twig-bundle Twig-to-JS bridge and executed in the browser by the Stimulus controller, so you can use Symfony Twig functions (path(), asset(), trans(), etc.) inside the blocks.
Row Actions
Add a non-searchable _actions column and render it with a <twig:block>:
row.rp contains the route parameters exposed in the serialized API response. Include the rp property in the entity's serialization group.
Stimulus helpers work too:
Offcanvas Detail Panel
Pass showRoute to add a "View" button per row. Clicking it fetches the route and renders the HTML in a Bootstrap Offcanvas panel — no page navigation.
The route receives row.rp as parameters. Add ?_page_content_only=1 handling in the controller/template to return only the content fragment.
Bulk Actions
Enable select=true and define bulkActions to let users select rows and POST their IDs to a server endpoint.
The controller receives ids[] (array of entity IDs) and className (FQCN) as a POST form submission. A CSRF token is included automatically.
Admin Browser
A generic admin browser route is registered at /admin/browse/{code}. The code is derived from the bundle/app prefix plus the entity short name:
Survos\OutreachBundle\Entity\Contact→/admin/browse/outreach_contactApp\Entity\Video→/admin/browse/app_video
/admin/browse lists all registered Doctrine entities.
If a route named {code}_show exists, the browser passes it as showRoute, enabling the offcanvas detail panel automatically.
Backend Filters
Repository facet counts
Facet counts (shown in ColumnControl dropdowns) require a repository method that can count distinct values per field. Install the trait from survos/core-bundle:
Pagination
The bundle's SlicePaginationExtension translates limit/offset from the DataTables request into Doctrine range queries. This runs automatically when the bundle is installed.
Further Reading
- docs/widgets.md — ColumnControl and SearchBuilder in depth
- docs/field-bundle.md — Attribute-driven configuration with
#[Field] - docs/implementation.md — Architecture: Twig component, Stimulus controller, normalizer, paginator
All versions of api-grid-bundle with dependencies
doctrine/doctrine-bundle Version ^3.0
doctrine/orm Version ^3.3
doctrine/persistence Version ^4.1
symfony/config Version ^8.1
symfony/dependency-injection Version ^8.1
symfony/http-kernel Version ^8.1
symfony/options-resolver Version ^8.1
symfony/ux-twig-component Version ^3
twig/twig Version ^3.4|^4.0
symfony/dom-crawler Version ^8.1
api-platform/symfony Version ^4.1 || ^5.0
survos/js-twig-bundle Version ^2.5
survos/kit-bundle Version ^2.5
survos/field-bundle Version ^2.5