dev-master
9999999-dev https://github.com/zunitec/DataTableBundleSymfony DataTableBundle
MIT
The Requires
- php >=5.3.3
- symfony/symfony 2.*
The Development Requires
- php >=5.3.3
- symfony/symfony 2.*
table datatable
Symfony DataTableBundle
/** * * @Route("/grid/ajax", name="cidade_grid") * @Secure(roles="ROLE_CIDADE_SHOW") */ public function gridAction(Request $request) { $dataTable = $this->createDataTable($request);, (*1)
$dataTable ->addColumn('id') ->addColumn('nome') ->addColumn('estado.nome') ->addColumnAction($this->getDataTableActionsDefault()) ; $dataTable->setDqlPart('{estado.nome} = :estadoNome'); $dataTable->setDqlParam(array('estadoNome' => 'sc')); return $this->getDataTableResponse($dataTable);
}, (*2)
{{ "cidade.id"|trans }} | {{ "cidade.nome"|trans }} | {{ "estado.titulo"|trans }} | {{"grid.acoes"|trans}} |
---|
/** * * Create new DataTable for response json * * @param \Symfony\Component\HttpFoundation\Request $request * @param string $condition DQL Contidion * @param arrray $paramCondition * @param type $entity * @return \Zuni\DataTableBundle\Entity\DataTable */ protected function createDataTable(Request $request, $condition = "", array $paramCondition = array(), $entity = null) { $entity = $entity ? $entity : $this->getNameEntity()." AS e";, (*3)
return new \Zuni\DataTableBundle\Entity\DataTable($request, $this->get("templating"), $this->getTwigLoaderString(), $entity);
}, (*4)
/** * * Create Data Table Response * * @param \Zuni\DataTableBundle\Entity\DataTable $dataTable * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function getDataTableResponse(\Zuni\DataTableBundle\Entity\DataTable $dataTable, $collectionsEntity = null ) { $arrayData = $dataTable->getData($this->getDoctrine()->getManager(), $collectionsEntity);, (*5)
return new JsonResponse($arrayData);
}, (*6)
/** * * Clona e modifica o twig do symfony para renderizar strings * * @return \Symfony\Bridge\Twig\TwigEngine */ protected function getTwigLoaderString() { $twigLoaderString = clone $this->get('twig'); $twigLoaderString->setLoader(new Twig_Loader_String());, (*7)
return $twigLoaderString;
}, (*8)
/** * * Retorna as açÔes padrão da entidade * * @todo Mudar as açÔes da DataTable para uma classe do bundle * @return array */ protected function getDataTableActionsDefault() { $entity = $this->getAliasEntity(); $entityUpperCase = strtoupper($entity);, (*9)
return array( 'show' => array( 'route' => $entity.'_show', 'role' => "ROLE_{$entityUpperCase}_SHOW" ), 'edit' => array( 'route' => $entity.'_edit', 'role' => "ROLE_{$entityUpperCase}_EDIT" ), 'delete' => array( 'route' => $entity.'_delete_ajax', 'role' => "ROLE_{$entityUpperCase}_EDIT" ), );
}, (*10)
Symfony DataTableBundle
MIT
table datatable