PHP code example of digipolisgent / datatables-bundle
1. Go to this page and download the library: Download digipolisgent/datatables-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digipolisgent / datatables-bundle example snippets
public function registerBundles()
{
$bundles = [
// other bundles
new DigipolisGent\DatatablesBundle\DatatablesBundle(),
];
}
class ProductDataExtractor implements DataExtractorInterface
{
// constructor etc.
public function extract(RequestInterface $request)
{
$query = $this->entityManager->createQuery('// some DQL');
$query->setMaxResults($request->getPageSize());
$query->setFirstResult($request->getOffset());
$paginator = new Paginator($query);
return new Extraction(
$paginator->getIterator()->getArrayCopy(),
$paginator->count()
);
}
}
$request->getSearch();
// ...
class ProductDataTableFactory
{
public static function create(Extractor $extractor)
{
$table = new DataTable('product', $extractor);
$table
->createColumn('owner', ['property' => 'owner.name'])
->createColumn('sku')
->createColumn('price')
->addColumn(new DateTimeColumn('created_at', ['format' => 'd-m-Y']))
;
return $table;
}
}
public function listAction()
{
retun $this->renderer->renderResponse('path/to/twig.html.twig', [
'table' => $this->get('app.datatable.table.product');
]);
}