PHP code example of inteve / datagrid
1. Go to this page and download the library: Download inteve/datagrid 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/ */
inteve / datagrid example snippets php
class MyPresenter extends Nette\Application\UI\Presenter
{
protected function createComponentGrid()
{
$datasource = new Inteve\DataGrid\DataSources\LeanMapperQuery($this->repository->queryAll(), $this->mapper);
$grid = new Inteve\DataGrid\DataGrid($datasource);
$grid->setTemplateFile(__DIR__ . '/@grid.latte'); // optional
$grid->setItemsOnPage(20, TRUE); // optional
$grid->addTextColumn('title', 'Title')
->setCustomRender(function (Entity\Post $post) {
$label = Html::el();
$label->addText($post->title);
return $label;
})
->setSortable();
$grid->addLinkColumn('url', 'URL');
$grid->addDateColumn('date', 'Date')
->setSortable();
$grid->addNumberColumn('views', 'Views')
->setSortable()
->setDecimals(1)
->setValueProvider(function (Entity\Post $post) {
return max(1, $post->views);
});
$grid->addAction('edit', 'Upravit', $this->lazyLink('edit'));
$grid->addAction('delete', 'Smazat', $this->lazyLink('delete!'));
$grid->addTextFilter('title', 'Title');
$grid->addTextFilter('url', 'URL');
$grid->setDefaultSort(array(
'date' => 'DESC',
'title' => 'ASC',
));
return $grid;
}
}