Statistics
2629
3
1
86d
Badges
Tags
grid
Dependencies

Build Status Latest Stable Version License Total Downloads Gitter

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

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
	 */
}
  • v2.0.0 v2.0.0

    • Added phpstan, code sniffer, updated to datagrid v6
  • v1.1.1 v1.1.1

  • v1.1.0 v1.1.0

    • Support for exactSearch/splitWordsSearch properties in FilterText (thanks @kuchy !)
  • v1.0.8 Compatibility with ublaboo/datagrid v5

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com