/doctrine-datatables

Helper library to implement doctrine powered server-side processing for jquery-datatables with joins, search, filtering and ordering.

Primary LanguagePHPMIT LicenseMIT

vaibhavpandeyvpz/doctrine-datatables

Helper library to implement Doctrine powered server-side processing for jquery-datatables with joins, search, filtering and ordering.

Latest Version Scrutinizer Code Quality SensioLabsInsight Total Downloads Software License

Install

composer require vaibhavpandeyvpz/doctrine-datatables

Usage with doctrine/dbal:

<?php

use Doctrine\DataTables;

$connection = /** instanceof Doctrine\DBAL\Connection */;

$datatables = (new DataTables\Builder())
    ->withIndexColumn('id')
    ->withQueryBuilder(
        $connection->createQueryBuilder()
            ->select('*')
            ->from('users')
    )
    ->withRequestParams($_GET);

echo json_encode($datatables->getResponse());

Usage with doctrine/orm:

<?php

use Doctrine\DataTables;

$em = /** instanceof Doctrine\ORM\EntityManager */;

$datatables = (new DataTables\Builder())
    ->withColumnAliases([
        'id' => 'u.id',
        'name' => 'u.name',
        'email' => 'u.email',
        'createdAt' => 'u.createdAt',
        'updatedAt' => 'u.updatedAt',
    ])
    ->withIndexColumn('u.id')
    ->withQueryBuilder(
        $em->createQueryBuilder()
            ->select('u')
            ->from(User::class, 'u'))
    ->withRequestParams($_GET);

echo json_encode($datatables->getResponse());

License

See LICENSE.md file.