mpetrini / doctrinedatatable
Bridge between jQuery Datatable ServerSide and Doctrine ORM
v0.9.0
2021-09-22 07:49 UTC
Requires
- php: ^7.2
- ext-json: *
- doctrine/dbal: ^2.4
- doctrine/orm: ^2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14@dev
- phan/phan: ^1.1
- pheromone/phpcs-security-audit: dev-master
- phpunit/phpunit: ^7.0
- sensiolabs/security-checker: ^5.0@dev
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.
