Streamlines the creation process of the data tables in Symfony applications.
About
·
Documentation
·
Reference
This bundle allows creating data tables in the same way as you probably do with forms, as every component can be defined with a type class and reused across the application.
Data tables can be sorted, filtered and paginated. Users can personalize the order and visibility of columns. Those features can be persisted between requests, per user, so closing the browser and coming back later will restore the previous state.
Works with Doctrine ORM and arrays out-of-the-box, but can be easily integrated with any data source. Supports theming with Twig and exporting to various data formats.
Warning
This bundle is still in development and is likely to change, or even change drastically. It is NOT production ready, and backwards compatibility is NOT guaranteed until the first stable release.
If you've ever worked with forms in Symfony, you should feel right at home:
class ProductDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder
->addColumn('id', NumberColumnType::class)
->addColumn('name', TextColumnType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('translation_domain', 'product');
}
}
Creating the data tables using those type classes may also seem very familiar:
class ProductController extends AbstractController
{
use DataTableFactoryAwareTrait;
public function index(Request $request, ProductRepository $repository): Response
{
$queryBuilder = $repository->createDataTableQueryBuilder();
$dataTable = $this->createDataTable(ProductDataTableType::class, $queryBuilder);
$dataTable->handleRequest($request);
if ($dataTable->isExporting()) {
return $this->file($dataTable->export());
}
return $this->render('product/index.html.twig', [
'products' => $dataTable->createView(),
])
}
}
Rendering the data table in Twig is as simple as executing a single function:
{# templates/product/index.html.twig #}
<div class="card">
{{ data_table(products, { title: 'Products' }) }}
</div>
The MIT License (MIT). Please see license file for more information.