mpetrini/doctrinedatatable

Bridge between jQuery Datatable ServerSide and Doctrine ORM

v0.9.0 2021-09-22 07:49 UTC

This package is auto-updated.

Last update: 2024-04-22 11:32:26 UTC


README

Latest Stable Version Project badge Project badge Project badge Project badge License

DoctrineDatatable

Deeply based on Doctrine2 package and jQueryDatatable. DoctrineDatatable attempts to take the pain out of development of datatable inside yours Web Application.

Requirements

DoctrineDatatable requires :

Install

composer require mpetrini/doctrinedatatable

Usage

Basic Usage

Unified Filter

<?php

use Doctrine\Tests\Models\CMS\CmsUser;
use DoctrineDataTable\Column;
use DoctrineDataTable\Datatable;

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

$datatable = new Datatable(
    $em->createQueryBuilder()
        ->select('u')
        ->from(CmsUser::class, 'u'),
    // Primary key of your datatable (Primary key of your entity most of the time)
    'id',
    array(
        new Column(
            // alias
            'name',
            // attribute name with table alias
            'u.name',
            // Where part of the DQL
            'u.name LIKE :global',
            // EQ / GTE / GT / LT / LIKE ...
            '%:global%'
        ),
        new Column(
            'status',
            'u.status',
            // Where part of the DQL
            'u.status LIKE :global',
            // EQ / GTE / GT / LT / LIKE ...
            '%:global%'
        ),
    )
);

echo json_encode(
    $datatable->setGlobalSearch(true)
        ->get($_GET)
);

Filter by column

<?php

use Doctrine\Tests\Models\CMS\CmsUser;
use DoctrineDataTable\Column;
use DoctrineDataTable\Datatable;

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

$datatable = new Datatable(
    $em->createQueryBuilder()
        ->select('u')
        ->from(CmsUser::class, 'u'),
    // Primary key of your datatable (Primary key of your entity most of the time)
    'id',
    array(
        new Column(
            // alias
            'name',
            // attribute name with table alias
            'u.name',
            // Where part of the DQL
            'u.name LIKE :name',
            // EQ / GTE / GT / LT / LIKE ...
            '%:name%'
        ),
        new Column(
            'status',
            'u.status'
            // Where And Resolve parts are optional if the column isn't filtered
        ),
    )
);

echo json_encode($datatable->get(
    $_GET
));

CSV Export

<?php

use Doctrine\Tests\Models\CMS\CmsUser;
use DoctrineDataTable\Column;
use DoctrineDataTable\Datatable;

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

$datatable = new Datatable(
    $em->createQueryBuilder()
        ->select('u')
        ->from(CmsUser::class, 'u'),
    'id',
    array(
        new Column(
            'name',
            'u.name',
            'u.name LIKE :name',
            '%:name%'
        ),
        new Column(
            'status',
            'u.status'
        ),
    )
);

echo $datatable->export();

Example

See examples directory.

License

See LICENSE.md file.