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

<?php

declare(strict_types = 1);

use TwiGrid\DataGrid;
use Nette\Database\Explorer;
use Nette\Database\Table\ActiveRow;
use Nette\Database\Table\Selection;


final class RowActionGrid extends DataGrid
{

	private Explorer $database;


	public function __construct(Explorer $database)
	{
		parent::__construct();

		$this->database = $database;
	}


	protected function build(): void
	{
		$this->setPrimaryKey('id');
		$this->addColumn('firstname', 'Name');
		$this->addColumn('surname', 'Surname');
		$this->addColumn('country_code', 'Country');
		$this->addColumn('birthday', 'Birthdate');

		$this->setDataLoader(function (array $filters, array $order): Selection {
			return $this->database->table('user')
				->limit(12);
		});

		$this->setRecordVariable('user');

		$this->addRowAction('download', 'Download', function (ActiveRow $user): void {
				$this->flashMessage("[DEMO] Downloading item '{$user->id}'...", 'success');
			})
			->setProtected(false); // turns off the CSRF protection which is not necessary here

		$this->addRowAction('delete', 'Delete', function (ActiveRow $user): void {
				$this->flashMessage("[DEMO] Deleting item '{$user->id}'...", 'success');
			})
			->setConfirmation('Do you really want to delete this item?');
	}

}