Statistics
2634
1
0
54d
Badges
Tags
grid
Dependencies

Build Status Latest Stable Version License Total Downloads Gitter

ElasticsearchDataSource

There is no problem using Elasticsearch as a data source for contributte/datagrid.

Installation

Download this package using composer:

composer require ublaboo/datagrid-elasticsearch-data-source

Usage

<?php

namespace App\Presenters;

use Elasticsearch\Client;
use Nette\Application\UI\Presenter;
use Ublaboo\DataGrid\DataGrid;
use Ublaboo\DatagridElasticsearchDataSource\ElasticsearchDataSource;

final class UsersPresenter extends Presenter
{

	/**
	 * @var ElasticsearchDataSource
	 */
	private $elasticsearchDataSource;


	public function __construct(Client $client)
	{
		$this->elasticsearchDataSource = new ElasticsearchDataSource(
			$client, // Elasticsearch\Client
			'users', // Index name
			'user' // Index type
		);
	}


	public function createComponentUsersGrid(): DataGrid
	{
		$grid = new DataGrid;

		$grid->setDataSource($this->elasticsearchDataSource);

		$grid->addColumnText('id', '#')->setSortable();
		$grid->addColumnLink('nickname', 'Nickname', 'edit')
			->setFilterText();
		$grid->addColumnText('username', 'E-mail (username)')
			->setFilterText();
		$grid->addColumnText('age', 'Age')
			->setSortable()
			->setFilterRange();
		$grid->addColumnText('status', 'Status')
			->setFilterMultiSelect([
				'active' => 'Active',
				'disabled' => 'Disabled',
			]);
		$grid->addColumnDateTime('created', 'Created')
			->setFormat('j. n. Y H:i:s')
			->setFilterDateRange();

		return $grid;
	}
}
  • v1.1.0 v1.1.0

    • Allow custom row factory for search result (thanks @MilanPala)
  • v1.0.0 v1.0.0

    First release

    • Complete ElasticsearchDataSource
    • Complete support class SearchParamsBuilder
    • Tests for SearchParamsBuilder

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

Componette Componette admin@componette.com