PHPackages                             saifuleroz/select2table-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. saifuleroz/select2table-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

saifuleroz/select2table-bundle
==============================

A Symfony bundle integrating Select2 as a high-performance remote AJAX drop-in replacement for standard entity/table select fields.

v2.0.0(today)01↑2900%MITPHPPHP &gt;=8.2

Since Aug 24Pushed today1 watchersCompare

[ Source](https://github.com/saifulferoz/select2table-bundle)[ Packagist](https://packagist.org/packages/saifuleroz/select2table-bundle)[ RSS](/packages/saifuleroz-select2table-bundle/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (14)Versions (2)Used By (0)

Select2TableBundle
==================

[](#select2tablebundle)

[![CI](https://github.com/saifuleroz/select2table-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/saifuleroz/select2table-bundle/actions)[![Latest Stable Version](https://camo.githubusercontent.com/93c2a40acfa557cd281c9e9dcccc9af5c4d50b527fb2aaf38266329b4bbe36ed/68747470733a2f2f706f7365722e707567782e6f72672f73616966756c65726f7a2f73656c656374327461626c652d62756e646c652f762f737461626c65)](https://packagist.org/packages/saifuleroz/select2table-bundle)[![Total Downloads](https://camo.githubusercontent.com/7ae08851e23762aacb65c549f1efac22f3eba00854fce41adb4dd1914e5f07c9/68747470733a2f2f706f7365722e707567782e6f72672f73616966756c65726f7a2f73656c656374327461626c652d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/saifuleroz/select2table-bundle)[![License](https://camo.githubusercontent.com/ddfa67f06af5485f06f56f8bfc81c9af996c1ccea8ffb4e69d5cf1a5ce167dfa/68747470733a2f2f706f7365722e707567782e6f72672f73616966756c65726f7a2f73656c656374327461626c652d62756e646c652f6c6963656e7365)](https://packagist.org/packages/saifuleroz/select2table-bundle)[![PHP Version](https://camo.githubusercontent.com/5f02ff435319bd3f497c11de572c9c7f258175e7c02482c49d4b7e0b25ed5fe4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e322d3838393242462e737667)](https://php.net)[![Symfony Version](https://camo.githubusercontent.com/0a3a9830ac950dc6902234423fb579975a6cbb2c697687d80365c742a0cfcb82/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d362e34253230253743253230372e34253230253743253230382e782d626c61636b2e737667)](https://symfony.com)

A high-performance Symfony bundle that integrates [Select2](https://select2.org/) as an asynchronous, remote-AJAX autocomplete replacement for standard table/entity select fields in Symfony forms.

> **Inspiration:** Inspired by [`tetranz/select2entity-bundle`](https://github.com/tetranz/select2entity-bundle), optimized with direct Doctrine DBAL performance, typed properties, strict typing, modern assets, and full support for **Symfony 7.4+** and **Symfony 8.x** (PHP 8.2+).

---

Key Features
------------

[](#key-features)

- ⚡ **High Performance:** Queries large database tables effortlessly with lightweight Doctrine DBAL pagination and count queries.
- 🔄 **Single &amp; Multi-Select:** Full support for `multiple: false` (single selection) and `multiple: true` (multi-selection).
- 📜 **Infinite Scrolling:** Server-side pagination with seamless incremental scrolling.
- 🔗 **Cascading / Dependent Dropdowns:** Reacts dynamically to changes in parent form fields (`req_params`).
- 🏷️ **Dynamic Tag Creation:** Allows users to create new tags on-the-fly (`allow_add`).
- 🎨 **HTML &amp; Custom Templating:** Render rich option templates (images, avatars, badges, icons).
- 🛠️ **Modern Asset Integration:** Compatible with **Symfony UX / AssetMapper**, **Webpack Encore**, **Vite**, and traditional CDN/Script setups.
- 🛡️ **SQL Injection Protection:** Validates identifiers and safely binds parameters across DBAL 3 &amp; DBAL 4.

---

Requirements
------------

[](#requirements)

- **PHP:** `^8.2 || ^8.3 || ^8.4 || ^8.5`
- **Symfony:** `^6.4 || ^7.4 || ^8.0`
- **Doctrine DBAL:** `^3.6 || ^4.0`
- **Twig:** `^3.0`
- **jQuery &amp; Select2 4.x**

---

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require saifuleroz/select2table-bundle
```

### 2. Enable the Bundle (if not using Symfony Flex)

[](#2-enable-the-bundle-if-not-using-symfony-flex)

If you are not using Symfony Flex, add the bundle to `config/bundles.php`:

```
return [
    // ...
    SaifulFeroz\Select2TableBundle\SaifulFerozSelect2TableBundle::class => ['all' => true],
];
```

### 3. Register the Twig Form Theme

[](#3-register-the-twig-form-theme)

Add the bundle's form theme in `config/packages/twig.yaml`:

```
twig:
    form_themes:
        - '@SaifulFerozSelect2Table/form/fields.html.twig'
```

---

Asset Setup
-----------

[](#asset-setup)

### Option A: Traditional / CDN Setup

[](#option-a-traditional--cdn-setup)

Ensure **jQuery** and **Select2** (CSS &amp; JS) are loaded on your page, then include the bundle's JavaScript:

```

```

Install the public bundle assets with:

```
php bin/console assets:install --symlink
```

### Option B: Symfony UX / AssetMapper (Stimulus)

[](#option-b-symfony-ux--assetmapper-stimulus)

Import the script in your `assets/app.js`:

```
import 'select2/dist/css/select2.min.css';
import 'select2';
import './vendor/saifuleroz/select2table-bundle/select2table.js';
```

---

Usage
-----

[](#usage)

### 1. Form Type Configuration

[](#1-form-type-configuration)

In your Symfony form class, use `Select2TableType::class`:

```
namespace App\Form;

use SaifulFeroz\Select2TableBundle\Form\Type\Select2TableType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class OrderType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('customer', Select2TableType::class, [
                'table_name'           => 'tbl_customers',
                'primary_key'          => 'id',
                'text_property'        => 'name',
                'property'             => ['name', 'email', 'phone'], // Searchable columns
                'remote_route'         => 'app_customer_autocomplete',
                'minimum_input_length' => 2,
                'page_limit'           => 10,
                'scroll'               => true,
                'allow_clear'          => true,
                'placeholder'          => 'Select a customer...',
            ]);
    }
}
```

### 2. Autocomplete Controller Endpoint

[](#2-autocomplete-controller-endpoint)

Create an autocomplete controller action and use the provided `AutocompleteService`:

```
namespace App\Controller;

use App\Form\OrderType;
use SaifulFeroz\Select2TableBundle\Service\AutocompleteService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

class AutocompleteController extends AbstractController
{
    #[Route('/autocomplete/customers', name: 'app_customer_autocomplete', methods: ['GET'])]
    public function customerAutocomplete(Request $request, AutocompleteService $autocompleteService): JsonResponse
    {
        $results = $autocompleteService->getAutocompleteResults($request, OrderType::class);

        return new JsonResponse($results);
    }
}
```

---

Configuration Reference
-----------------------

[](#configuration-reference)

You can customize global defaults in `config/packages/saifulferoz_select2_table.yaml`:

```
saifulferoz_select2_table:
    minimum_input_length: 1       # Characters before triggering search
    page_limit: 10                # Number of records per page
    scroll: false                 # Enable infinite scrolling
    allow_clear: false            # Show clear ('x') button
    delay: 250                    # Debounce delay in milliseconds
    language: 'en'                # Select2 language code
    theme: 'default'              # Select2 theme (e.g. 'default', 'bootstrap-5')
    cache: true                   # Client-side AJAX cache
    cache_timeout: 60000          # Cache lifetime in ms (0 = indefinite)
    table_name: null              # Default table name
    text_property: null           # Default column for text label
    primary_key: 'id'             # Default primary key column
    width: null                   # CSS width (e.g. '100%', 'resolve')
    render_html: false            # Allow HTML rendering in results
    allow_add:
        enabled: false            # Enable new tag creation
        new_tag_text: ' (NEW)'    # Text appended to new tags
        new_tag_prefix: '__'      # Prefix added to submitted value
        tag_separators: '[",", " "]'
```

---

Advanced Recipes
----------------

[](#advanced-recipes)

### 1. Cascading / Dependent Dropdowns (`req_params`)

[](#1-cascading--dependent-dropdowns-req_params)

When selecting a City that depends on the chosen Country, specify `req_params`:

```
$builder
    ->add('country', Select2TableType::class, [
        'table_name'   => 'tbl_countries',
        'remote_route' => 'app_autocomplete',
        'property'     => 'name',
    ])
    ->add('city', Select2TableType::class, [
        'table_name'   => 'tbl_cities',
        'remote_route' => 'app_autocomplete',
        'property'     => 'name',
        'req_params'   => ['country_id' => 'parent.children[country]'],
        'callback'     => function (\Doctrine\DBAL\Query\QueryBuilder $qb, $request): void {
            if ($countryId = $request->get('country_id')) {
                $qb->andWhere('country_id = :country_id')
                   ->setParameter('country_id', $countryId);
            }
        },
    ]);
```

### 2. Multi-Column Search &amp; Custom Filtering Callbacks

[](#2-multi-column-search--custom-filtering-callbacks)

Search across multiple columns (e.g. `first_name`, `last_name`, `email`) and filter active rows:

```
$builder->add('agent', Select2TableType::class, [
    'table_name'    => 'tbl_agents',
    'primary_key'   => 'id',
    'text_property' => 'full_name',
    'property'      => ['first_name', 'last_name', 'email'],
    'remote_route'  => 'app_agent_autocomplete',
    'callback'      => function (\Doctrine\DBAL\Query\QueryBuilder $qb, $request): void {
        $qb->andWhere('is_active = :active')
           ->setParameter('active', 1);
    },
]);
```

### 3. Rich HTML Results &amp; Avatar Icons

[](#3-rich-html-results--avatar-icons)

Set `render_html: true` on your form field:

```
$builder->add('member', Select2TableType::class, [
    'table_name'   => 'tbl_members',
    'remote_route' => 'app_member_autocomplete',
    'property'     => 'username',
    'render_html'  => true,
]);
```

In your controller, return an `html` property in the row array:

```
// In custom repository or callback query:
$results = [
    'results' => [
        [
            'id' => 1,
            'text' => 'Jane Doe',
            'html' => ' Jane Doe Admin'
        ]
    ],
    'more' => false,
];
```

### 4. Embedded Collection Form Support

[](#4-embedded-collection-form-support)

If using Symfony Form Collections with `data-prototype` or dynamic additions, `select2table.js` automatically detects newly added elements and initializes them without extra code.

---

Backward Compatibility
----------------------

[](#backward-compatibility)

For smooth upgrades from legacy versions:

- Legacy namespace `Feroz\Select2TableBundle\` classes and service aliases remain intact.
- Legacy form theme block `{% block feroz_select2table_widget %}` delegates automatically to `saifulferoz_select2table_widget`.
- Legacy configuration key `feroz_select2_table` is fully supported.

---

Testing
-------

[](#testing)

Run the PHPUnit test suite:

```
composer test
```

---

License
-------

[](#license)

This bundle is open-sourced software licensed under the [MIT License](LICENSE).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/42f7ccbb50ac26336f56240519756fffae416abcdc6ff44540947bd2cc941487?d=identicon)[saifulferoz](/maintainers/saifulferoz)

---

Top Contributors

[![saifulferoz](https://avatars.githubusercontent.com/u/15348453?v=4)](https://github.com/saifulferoz "saifulferoz (12 commits)")

---

Tags

symfonyautocompletedoctrinedbalajaxformtypeaheadSymfony Bundleselect2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/saifuleroz-select2table-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/saifuleroz-select2table-bundle/health.svg)](https://phpackages.com/packages/saifuleroz-select2table-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k18.3M432](/packages/easycorp-easyadmin-bundle)[chameleon-system/chameleon-base

The Chameleon System core.

1029.4k6](/packages/chameleon-system-chameleon-base)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k6.0M780](/packages/sylius-sylius)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.8M683](/packages/shopware-core)[contao/core-bundle

Contao Open Source CMS

1301.7M3.1k](/packages/contao-core-bundle)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.9M536](/packages/pimcore-pimcore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
