This repository has been archived by the owner on Dec 31, 2019. It is now read-only.
forked from AliHichem/AliDatatableBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
How to include the use of doctrine query builder
benjaminu edited this page Dec 5, 2012
·
3 revisions
To use your own query object to supply to the datatable object, you can perform this action using your proper "doctrine query object": AliDatatableBundle allow (since tag 1.2.0) to manipulate the query object provider which is now a doctrine query builder object, you can use it to update the query in all its components except of course in the selected field part.
This is a classic config before using the doctrine query builder:
private function _datatable()
{
$datatable = $this->get('datatable')
->setEntity('XXXBundle:Entity', 'e')
->setFields(
array(
'column1 label' => 'e.column1',
'_identifier_' => 'e.id'
)
)
->setWhere(
'e.column1 = :column1',
array('column1' => '1')
)
->setOrder('e.created', 'desc');
$qb = $datatable->getQueryBuilder()->getDoctrineQueryBuilder();
// This is the doctrine query builder object , you can
// retrieve it and include your own change
return $datatable;
}
This is a config that uses a doctrine query object a query builder :
private function _datatable()
{
$qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder();
$qb->from('XXXBundle:Entity', 'e')
->where('e.column1 = :column1')
->setParameters(array('column1' => 0))
->orderBy('e.created', 'desc');
$datatable = $this->get('datatable')
->setFields(
array(
'Column 1 label' => 'e.column1',
'_identifier_' => 'e.id'
)
);
$datatable->getQueryBuilder()->setDoctrineQueryBuilder($qb);
return $datatable;
}