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

Hide show specific columns (visibility)

benjaminu edited this page Dec 6, 2012 · 2 revisions

By default the all columns field columns set are displayed; however, sometimes you may want to pull some data, but not necessarily display such data. Rather you may want to use such data for some background processing/formatting. To do hide such columns, you just need to activate it from your configuration method as follows:
    $controllerInstance = $this;

    return $this->get('datatable')
        ->setEntity($this->_entity_name, 'entity')
        ->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 Id'     => 'g.id',
                'Group'        => 'g.name',
                'Team Id'      => 't.id',
                '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.adress = :adress',
            array('adress' => 'Paris') 
        )
        ->setRenderer(
            function (&$data) use ($controllerInstance) {
                foreach ($data as $key => $value) {
                    if ($key == 3 || $key == 5) {
                        $data[$key] = $controllerInstance
                            ->get('templating')
                            ->render(
                                'XXXBundle:partials:something.html.twig',
                                array('id' => $data[$key-1], 'name' => $value)
                        );
                    }
                }
            }
        )
        ->setColumnVisibilityStatus(array(2 => false, 4 => false)); // Disable sorting on 'g.id', and 't.id' columns.