incorporate DatatablesNet, using twig and stimulus, twig_component requires ^2.2

Fund package maintenance!

Installs: 2 340

Dependents: 0

Suggesters: 1

Security: 0

Stars: 2

Watchers: 4

Forks: 0

Open Issues: 2


1.5.253 2024-07-12 20:50 UTC

This package is auto-updated.

Last update: 2024-07-12 20:50:46 UTC


Use the javascript library with Symfony, Twig and API Platform. requires survos/grid-bundle, which loads the datatables libraries.

composer req survos/api-grid-bundle


Import the datasets at

Dev only...

composer config repositories.survos_grid_bundle '{"type": "vcs", "url": ""}'


Inorder to use api-grid we need to follow below:

1) Add Survos\CoreBundle\Traits\QueryBuilderHelperTrait in your repository class of the entity for which you want apiGrid

2) you need to set columns variable like below:

        {% set columns = [
        {name: 'code', sortable: true},
        {name: 'countrycode', sortable: true,  browsable: true, searchable: true},
        {name: 'privacyPolicy', browsable: true},
        {name: 'projectLocale', browsable: true},
        ] %}

By default, sortable, browsable, searchable are false.

For those columns you want sortable add sortable: true

For those columns you want to add searchPanes add browsable: true

For those columns you want to add searchable: true

3) For search you need to include below

use Survos\ApiGrid\Api\Filter\MultiFieldSearchFilter;

#[ApiFilter(MultiFieldSearchFilter::class, properties: ['name', 'code'])]
#[ApiFilter(MultiFieldSearchFilter::class, properties: ['firstName', 'lastName', 'officialName'])]
#[ApiFilter(FacetsFieldSearchFilter::class, properties: ['gender', 'currentParty'])]

Here name and code are columns in which you need to search

4) Use below for doctrine searchpane filters

First, make sure you have the necessary counts method by adding the helper trait to the repository class

class OfficialRepository extends ServiceEntityRepository implements QueryBuilderHelperInterface
    use QueryBuilderHelperTrait;

Then add the filterable properties to the entity class. You may want to index them to speed up the count query

use Survos\ApiGrid\Api\Filter\FacetsFieldSearchFilter;

#[ApiFilter(FacetsFieldSearchFilter::class, properties: ['gender','state'])]

5) Use below for doctrine order filters

use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;

#[ApiFilter(OrderFilter::class, properties: ['id','objectCount','countryCode'])]
symfony new phpunit-bug --webapp && cd phpunit-bug
composer require --dev symfony/phpunit-bridge

API Bug with doctrine

symfony new api-bug --webapp && cd api-bug
composer config extra.symfony.allow-contrib true
echo "DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db" > .env.local
composer require api
echo "title,string,80,yes," | sed "s/,/\n/g"  | bin/console -a make:entity Book
bin/console doctrine:schema:update --force --complete

symfony server:start -d
symfony open:local --path=/api

Now add a Book via post

curl -X 'POST' \
  '' \
  -H 'accept: application/ld+json' \
  -H 'Content-Type: application/ld+json' \
  -d '{
  "title": "Symfony Fast Track"

Brainstorm: jstwig component

<twig:jstwig :data="data>
<section class="containers">
            {{ row.s|length }} Results

    {% for row in row %}
                {{- 'Overlay ' ~ i -}}
    {% endfor %}