Tip: Press Shift to (un)check multiple rows.
Tip: Clicking in the header row checks all rows.
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

# GroupActionGrid.php

<?php

declare(strict_types = 1);

use Nette\Utils\Json;
use TwiGrid\DataGrid;
use Nette\Database\Explorer;
use Nette\Database\Table\Selection;


final class GroupActionGrid 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->addGroupAction('export', 'Export', function (array $users): void {
			$IDs = [];
			foreach ($users as $user) {
				$IDs[] = $user->id;
			}

			$this->flashMessage('[DEMO] Exporting items ' . Json::encode($IDs), 'success');
		});

		$this->addGroupAction('delete', 'Delete', function (array $users): void {
				$ids = [];
				foreach ($users as $user) {
					$ids[] = $user->id;
				}

				$this->flashMessage('[DEMO] Deleting items ' . Json::encode($ids), 'success');
			})
			->setConfirmation('Do you really want to delete all chosen items?');
	}

}