PHP code example of vysokeskoly / data-grid-bundle
1. Go to this page and download the library: Download vysokeskoly/data-grid-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/ */
vysokeskoly / data-grid-bundle example snippets
$bundles = [
...
new Kitpages\DataGridBundle\KitpagesDataGridBundle(),
];
use Kitpages\DataGridBundle\Grid\GridConfig;
use Kitpages\DataGridBundle\Grid\Field;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ContactController
{
public function productListAction(Request $request): Response
{
// create query builder
$repository = $this->getDoctrine()->getRepository('AcmeStoreBundle:Product');
$queryBuilder = $repository->createQueryBuilder('item')
->where('item.price > :price')
->setParameter('price', '19.90')
;
$gridConfig = new GridConfig($queryBuilder, 'item.id');
$gridConfig
->addField('item.id')
->addField('item.slug', ['filterable' => true])
->addField('item.updatedAt', [
'sortable' => true,
'formatValueCallback' => fn ($value) => $value->format('Y/m/d')
])
;
$gridManager = $this->get('kitpages_data_grid.grid_manager');
$grid = $gridManager->getGrid($gridConfig, $request);
return $this->render('AppSiteBundle:Default:productList.html.twig', [
'grid' => $grid
]);
}
}
// add tag as the third parameter of the field
$gridConfig->addField("item.id", [], ['foo', 'bar']);
$gridConfig->addField("foo", [], ['myTag', 'foo']);
// get fieldList matching 'bar' tag. There is only one result.
$fieldList = $gridConfig->getFieldListByTag('bar');
$fieldList[0] // -> this is the first Field (which name is 'item.id')
class CustomGrid extends Grid
{
public $myParameter;
}
$myCustomGrid = new CustomGrid();
$grid = $gridManager->getGrid($gridConfig, $request,$myCustomGrid);
// now the $grid object is an instance of CustomGrid (it
// is exactly the same object than $myCustomGrid, not cloned)
$gridConfig->addField('slug', [
'label' => 'Mon slug',
'sortable' => false,
'visible' => true,
'filterable' => true,
'translatable' => true,
'formatValueCallback' => fn ($value) => strtoupper($value),
'autoEscape' => true,
'category' => null, // only used by you for checking this value in your events if you want to...
'nullIfNotExists' => false, // for leftJoin, if value is not defined, this can return null instead of an exception
]);
$gridConfig->addField('slug', [
FieldOption::Label->value => 'Mon slug',
FieldOption::Sortable->value => false,
FieldOption::Visible->value => true,
FieldOption::Filterable->value => true,
FieldOption::Translatable->value => true,
FieldOption::FormatValueCallback->value => fn ($value) => strtoupper($value),
FieldOption::AutoEscape->value => true,
FieldOption::Category->value => null, // only used by you for checking this value in your events if you want to...
FieldOption::NullIfNotExists->value => false, // for leftJoin, if value is not defined, this can return null instead of an exception
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.