Name
Surname
Country
Birthdate
 
Martina Trommler is 1964-10-25
Marij Rašpolić ca 1972-12-16
Lyyli Vaara fi 1963-05-05
Dýrleif Björnsdóttir it 1972-11-24
Martha Yohannes pl 1966-11-05
Amadi Onyekachukwu it 1981-07-09
Satu Tukio au 1975-03-25
Mary Black is 1994-12-15
Consuela Takens is 1993-01-20
Aaya Weerdenburg it 1970-05-04
Ormos Széll pl 1993-01-31
Hrvojka Petković fi 1962-09-30

Code

# RowActionGrid.php


class RowActionGrid extends BaseGrid
{

	/** @return void */
	protected function build()
	{
		parent::build();

		$this->setPrimaryKey('id');
		$this->addColumn('firstname', 'Name');
		$this->addColumn('surname', 'Surname');
		$this->addColumn('country_code', 'Country');
		$this->addColumn('birthday', 'Birthdate');

		$this->addRowAction('download', 'Download', [$this, 'downloadItem'])
			->setProtected(FALSE); // turns off the CSRF protection which is not necessary here

		$this->addRowAction('delete', 'Delete', [$this, 'deleteItem'])
			->setConfirmation('Do you really want to delete this item?');

		$this->setDataLoader([$this, 'dataLoader']);
	}


	/**
	 * @param  RowActionGrid $grid
	 * @param  array $filters
	 * @param  array $order
	 * @return Nette\Database\Table\Selection
	 */
	public function dataLoader(RowActionGrid $grid, array $filters, array $order)
	{
		return $this->database->table('user')
				->limit(12);
	}


	/**
	 * @param  Nette\Database\Table\ActiveRow $record
	 * @return void
	 */
	public function downloadItem(Nette\Database\Table\ActiveRow $record)
	{
		$this->flashMessage("[DEMO] Downloading item '{$record->id}'...", 'success');
	}


	/**
	 * @param  Nette\Database\Table\ActiveRow $record
	 * @return void
	 */
	public function deleteItem(Nette\Database\Table\ActiveRow $record)
	{
		$this->flashMessage("[DEMO] Deleting item '{$record->id}'...", 'success');
	}

}
	

# BaseGrid.php


use Nette\Http\Session as NSession;
use Nette\Database\Context as NdbContext;


abstract class BaseGrid extends TwiGrid\DataGrid
{

	/** @var NdbContext */
	protected $database;


	/**
	 * @param  NSession $session
	 * @param  NdbContext $database
	 */
	public function __construct(NSession $session, NdbContext $database)
	{
		parent::__construct($session);
		$this->database = $database;
	}


	/** @return void */
	protected function build()
	{
		parent::build();
		$this->setRecordVariable('user');
	}

}