Build Status (opens new window) Latest Stable Version (opens new window) License (opens new window) Total Downloads (opens new window) Gitter (opens new window)

# Nette\Database data source for Nette\Database

Utility that makes possible to use Nette\Database native query with Ublaboo\DataGrid

If you are using Nette\Database instead of Nette\Database\Table (probably because of the need to create more complex queries), there was an option to call ResultSet::fetchAll() and operate with that array.

But why should you fetch all data from the database to show just a few of them?

# Installation

Download this package using composer:

composer require ublaboo/datagrid-nette-database-data-source
1

# Usage

/**
 * @var Nette\Database\Context
 * @inject
 */
public $ndb;


public function createComponentNetteGrid($name)
{
	/**
	 * @type Ublaboo\DataGrid\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 (product.status = ? OR product.status = ?)';

	$params = [1, 2];

	/**
	 * @var Ublaboo\NetteDatabaseDataSource\NetteDatabaseDataSource
	 * 
	 * @param Nette\Database\Context
	 * @param $query
	 * @param $params|NULL
	 */
	$datasource = new NetteDatabaseDataSource($this->ndb, $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 => 'Ofline', 2 => 'Standby']);

	/**
	 * Etc
	 */
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53