Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inteve/datagrid
Simple datagrid for Nette applications.
https://github.com/inteve/datagrid
datagrid nette nette-component php
Last synced: about 2 months ago
JSON representation
Simple datagrid for Nette applications.
- Host: GitHub
- URL: https://github.com/inteve/datagrid
- Owner: inteve
- License: other
- Created: 2019-10-18T11:29:00.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-05T11:43:30.000Z (about 1 year ago)
- Last Synced: 2024-10-07T19:37:23.621Z (3 months ago)
- Topics: datagrid, nette, nette-component, php
- Language: PHP
- Homepage:
- Size: 71.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license.md
Awesome Lists containing this project
README
# Inteve\Datagrid
[![Build Status](https://github.com/inteve/datagrid/workflows/Build/badge.svg)](https://github.com/inteve/datagrid/actions)
[![Downloads this Month](https://img.shields.io/packagist/dm/inteve/datagrid.svg)](https://packagist.org/packages/inteve/datagrid)
[![Latest Stable Version](https://poser.pugx.org/inteve/datagrid/v/stable)](https://github.com/inteve/datagrid/releases)
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/inteve/datagrid/blob/master/license.md)DataGrid component for Nette.
## Installation
[Download a latest package](https://github.com/inteve/datagrid/releases) or use [Composer](http://getcomposer.org/):
```
composer require inteve/datagrid
```Inteve\Datagrid requires PHP 7.2.0 or later.
## Usage
In presenter:
``` 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;
}
}
```In template:
```latte
{control grid}
```------------------------------
License: [New BSD License](license.md)
Author: Jan Pecha, https://www.janpecha.cz/