Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

Advanced use of datatable

benjaminu edited this page Dec 6, 2012 · 4 revisions

Assuming the example above, you can add your joins and where statements

    /**
     * set datatable configs
     * 
     * @return \Ali\DatatableBundle\Util\Datatable
     */
    private function _datatable()
    {
        return $this->get('datatable')
            ->setEntity('XXXMyBundle:Entity', 'x') // replace 'XXXMyBundle:Entity' by your entity
            ->setFields(
                array(
                    'Name'         => 'x.name', // Declaration for fields: 
                    'Address'      => 'x.address', // 'label' => 'alias.field_attribute_for_dql'
                    'Group'        => 'g.name',
                    'Team'         => 't.name',
                    '_identifier_' => 'x.id' // you have to put the identifier field without label. Do not replace the '_identifier_'
                )                         
            )
            ->addJoin('x.group', 'g', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
            ->addJoin('x.team', 't', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
            ->setWhere( // set your dql where statement
                'x.address = :address',
                array('address' => 'Paris') 
            )
            ->setOrder('x.created', 'desc')  // it's also possible to set the default order
            ->setHasAction(true);  // you can disable action column from here by setting 'false'.
    }