Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions .docs/README.md

This file was deleted.

76 changes: 66 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,81 @@
Website 🚀 <a href="https://contributte.org">contributte.org</a> | Contact 👨🏻‍💻 <a href="https://paveljanda.com">paveljanda.com</a>, <a href="https://f3l1x.io">f3l1x.io</a> | Twitter 🐦 <a href="https://twitter.com/contributte">@contributte</a>
</p>

## Usage
Nette Database data source adapter for [ublaboo/datagrid](https://github.com/contributte/datagrid), useful for grids backed by custom SQL queries.

## Versions

To install latest version of `contributte/datagrid-nette-database-data-source` use [Composer](https://getcomposer.org).
| State | Version | Branch | PHP |
|--------|---------|--------|------|
| dev | ~3.0.0 | master | ^7.2 |
| stable | ~2.0.0 | master | ^7.2 |
| stable | ~1.1.0 | master | ^5.6 |

## Installation

To install latest version of `ublaboo/datagrid-nette-database-data-source` use [Composer](https://getcomposer.org).

```bash
composer require ublaboo/datagrid-nette-database-data-source
```

## Documentation
## Usage

For details on how to use this package, check out our [documentation](.docs).
Use this data source when your grid is backed by a custom SQL query instead of a Nette Database selection. Pass the Nette Database connection, SQL, and parameters to `NetteDatabaseDataSource`, then configure the grid normally.

## Versions
```php
use Nette\Database\Context;
use Ublaboo\DataGrid\DataGrid;
use Ublaboo\NetteDatabaseDataSource\NetteDatabaseDataSource;

final class ProductPresenter extends Nette\Application\UI\Presenter
{
/** @var Context */
private $database;

public function __construct(Context $database)
{
$this->database = $database;
}

public function createComponentNetteGrid(string $name): DataGrid
{
$grid = new DataGrid($this, $name);

$query =
'SELECT p.*, GROUP_CONCAT(v.code SEPARATOR ", ") AS variants
FROM product p
LEFT JOIN product_variant p_v
ON p_v.product_id = p.id
WHERE p.deleted IS NULL
AND (p.status = ? OR p.status = ?)';

| State | Version - | Branch | PHP |
|--------|------------|--------|------|
| dev | ~3.0.0 | master | ^7.2 |
| stable | ~2.0.0 | master | ^7.2 |
| stable | ~1.1.0 | master | ^5.6 |
$params = [1, 2];

$datasource = new NetteDatabaseDataSource($this->database, $query, $params);

$grid->setDataSource($datasource);

$grid->addColumnText('name', 'Name')
->setSortable();

$grid->addColumnNumber('id', 'Id')
->setSortable();

$grid->addColumnDateTime('created', 'Created');

$grid->addFilterDateRange('created', 'Created:');

$grid->addFilterText('name', 'Name and id', ['id', 'name']);

$grid->addFilterSelect('status', 'Status', ['' => 'All', 1 => 'Online', 0 => 'Offline', 2 => 'Standby']);

// Add more columns, filters, and actions as needed.

return $grid;
}
}
```


## Development
Expand Down