PHP code example of deviantlab / tabulator-bundle

1. Go to this page and download the library: Download deviantlab/tabulator-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

deviantlab / tabulator-bundle example snippets


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;
    }
}

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,
        ]);
    }
}

use DeviantLab\TabulatorBundle\FilterFunction;
use DeviantLab\TabulatorBundle\Server\Filter\FilterOverride;
use DeviantLab\TabulatorBundle\Server\Sorter\SortOverride;

public function getSortOverride(): ?SortOverride
{
    return (new SortOverride())->add('fullName', function (QueryBuilder $qb, string $field, string $dir) {
        $qb->addOrderBy('CONCAT(p.firstName, p.lastName)', $dir);
    });
}

public function getFilterOverride(): ?FilterOverride
{
    return (new FilterOverride())->add('fullName', FilterFunction::LIKE, function (QueryBuilder $qb, mixed $value) {
        $qb->andWhere('CONCAT(p.firstName, p.lastName) LIKE :fullName')
            ->setParameter('fullName', "%{$value}%");
    });
}