PHP code example of intracto / datatables-backend
1. Go to this page and download the library: Download intracto/datatables-backend 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/ */
intracto / datatables-backend example snippets
class AddressListColumnTransformer implements ColumnTransformerInterface
{
/**
* @var EngineInterface
*/
private $renderEngine;
/**
* AddressListColumnTransformer constructor
*
* @param EngineInterface $renderEngine
*/
public function __construct(EngineInterface $renderEngine)
{
$this->renderEngine = $renderEngine;
}
/**
* @param array $data
*
* @return array
*/
public function transform(array $data)
{
$columns = array();
foreach ($data as $address) {
/**
* @var Address $address
*/
$columns[] = array(
$address->getCity()
$address->getZip()
$address->getStreet()
$this->renderEngine->render('Address/_list.actions.html.twig', array('address' => $address)),
);
}
return $columns;
}
}
public function listAction()
{
$columns = new AddressListColumns();
return array(
'columns' => $columns,
);
}
public function ajaxListAction(Request $request)
{
$parameters = Parameters::fromParameterBag($request->query, new AddressListColumns());
$data = $this->dataTablesDataProvider->getData(
$parameters,
$addressRepository,
$addressListColumnTransformer
);
return new JsonResponse($data);
}