PHPackages                             deviantlab/tabulator-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. [Framework](/categories/framework)
4. /
5. deviantlab/tabulator-bundle

ActiveSymfony-bundle[Framework](/categories/framework)

deviantlab/tabulator-bundle
===========================

Tabulator Symfony bundle

0.4.4(1y ago)51.5k2MITPHPPHP &gt;=8.1

Since Aug 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/6insanes/tabulator-bundle)[ Packagist](https://packagist.org/packages/deviantlab/tabulator-bundle)[ RSS](/packages/deviantlab-tabulator-bundle/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (8)Versions (20)Used By (0)

Ux Tabulator Bundle
===================

[](#ux-tabulator-bundle)

A Symfony bundle that integrates [Tabulator](https://tabulator.info/) (a JavaScript table/datagrid library) into Symfony applications via Stimulus. Tables are declared as PHP classes, rendered with a single Twig function, and — for server-side pagination/sorting/filtering — backed by an auto-registered controller that queries Doctrine ORM entities or native DBAL connections on your behalf.

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

[](#installation)

**Before you start, make sure you have [StimulusBundle](https://symfony.com/bundles/StimulusBundle/current/index.html) configured in your app.**

Install the bundle using Composer and Symfony Flex:

```
composer require deviantlab/tabulator-bundle
```

If you're using WebpackEncore, install your assets and restart Encore (not needed if you're using AssetMapper):

```
npm install --force
npm run watch

# or use yarn
yarn install --force
yarn watch
```

Usage
-----

[](#usage)

### 1. Define a table type

[](#1-define-a-table-type)

A table is described by a class implementing `TableInterface`. The bundle ships two abstract base classes depending on your data source:

- `AbstractOrmTableType` — builds a Doctrine ORM `QueryBuilder` against an entity.
- `AbstractNativeTableType` — builds a `Doctrine\DBAL\Query\QueryBuilder` against a raw DBAL connection (no entity mapping required).

Any service tagged (auto-configured) with `TableInterface` is automatically registered as a `deviantlab.tabulator.table_type`, so as long as autowiring/autoconfiguration is enabled for your services, no extra wiring is needed.

```
namespace App\Table;

use App\Entity\Product;
use DeviantLab\TabulatorBundle\AbstractOrmTableType;
use DeviantLab\TabulatorBundle\Column;
use DeviantLab\TabulatorBundle\FilterMode;
use DeviantLab\TabulatorBundle\Pagination;
use DeviantLab\TabulatorBundle\PaginationMode;
use DeviantLab\TabulatorBundle\SortMode;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

final class ProductTable extends AbstractOrmTableType
{
    public static function getName(): string
    {
        return 'product_table';
    }

    public function getEntityClass(): string
    {
        return Product::class;
    }

    public function getQueryBuilder(EntityRepository $repo, array $params): QueryBuilder
    {
        return $repo->createQueryBuilder('p');
    }

    public function getColumns(): iterable
    {
        yield new Column('Name', 'name');
        yield new Column('Price', 'price', hozAlign: \DeviantLab\TabulatorBundle\HozAlign::RIGHT);
    }

    public function getPagination(): ?Pagination
    {
        return new Pagination(mode: PaginationMode::REMOTE, size: 20);
    }

    public function getSortMode(): SortMode
    {
        return SortMode::REMOTE;
    }

    public function getFilterMode(): FilterMode
    {
        return FilterMode::REMOTE;
    }
}
```

The `getName()` value must be unique across all table types — it identifies the table in the auto-generated data endpoint (`/{_tableName}`, route `deviantlab_tabulatorbundle_get_data`) and is used to resolve the type from the container.

For a native/DBAL-backed table, extend `AbstractNativeTableType` instead and implement `getConnectionName()` and `getQueryBuilder(Connection $connection, array $params)`.

### 2. Build and render the table

[](#2-build-and-render-the-table)

Use `TableFactory` to turn a table type into a `Table` instance (this also wires up the Ajax endpoint automatically), then render it with the `render_table()` Twig function:

```
use App\Table\ProductTable;
use DeviantLab\TabulatorBundle\TableFactory;

final class ProductController
{
    public function list(TableFactory $tableFactory): Response
    {
        $table = $tableFactory->create(ProductTable::class, params: ['categoryId' => 5]);

        return $this->render('product/list.html.twig', [
            'table' => $table,
        ]);
    }
}
```

```
{{ render_table(table) }}
```

This renders a single `` with Stimulus controller attributes; the `deviantlab--tabulator-bundle--tabulator` Stimulus controller (bundled in `assets/dist/tabulator_controller.js`) reads the serialized options and boots the Tabulator instance in the browser.

### 3. Configuring columns

[](#3-configuring-columns)

`Column` maps closely to Tabulator's own column definition options (`title`, `field`, `width`, `widthGrow`, `widthShrink`, `resizable`, `minWidth`, `maxWidth`, `frozen`, `headerSort`, `headerHozAlign`, `hozAlign`, `vertAlign`, `print`, etc.) plus a set of strategy objects:

- `formatter` / `topCalcFormatter` / `bottomCalcFormatter` — any `FormatterInterface`(e.g. `HtmlFormatter`, `LinkFormatter`, `MoneyFormatter`, `DateTimeFormatter`, `TickCrossFormatter`, `RowNumFormatter`, `RowSelectionFormatter`, `TextAreaFormatter`).
- `editor` — any `EditorInterface` (e.g. `InputEditor`, `TextareaEditor`, `NumberEditor`, `SelectEditor`, `CheckboxEditor`, `DateEditor`, `DateTimeEditor`, `TimeEditor`, `RangeEditor`, `StarRatingEditor`, `ProgressBarEditor`).
- `mutator` / `accessor` — any `MutatorInterface` / `AccessorInterface`.
- `sorter` — any `SorterInterface` (e.g. `AlphanumericSorter`, `NumberSorter`, `StringSorter`, `DateSorter`, `DateTimeSorter`, `TimeSorter`, `BooleanSorter`, `ArraySorter`, `ExistsSorter`).
- `validator` — a single `ValidatorInterface` or array of them (e.g. `Required`, `MinLength`, `MaxLength`).
- `topCalc` / `bottomCalc` — a `ColumnCalculationInterface` (`Sum`, `Average`, `Count`, `Minimum`, `Maximum`, `Unique`, `Concatenate`).
- `headerFilter` — a `HeaderFilter` combining an editor, a `FilterFunction`(`=`, `!=`, `starts`, `ends`, `>`, `=`, `
