Group actions:
Id Name sha1(name) Inserted
1 6r0xliyalt 49d7b59abf300db8b63302d5a9765bc9f1b74ad2 6. 2. 2015
2 ozl4gy9udu 6fe74b5954c7b80fbd62d3b0a4c0b4162f8e361f 6. 2. 2015
3 9i20xsrese f02bbf4683fad8bcfffff1e32f6a3111381dbd84 6. 2. 2015
4 yk95ak88ra 8b79c36df70304470f5a0fbcb8363ea045ad1d78 6. 2. 2015
5 2loxs05egs 990361b4700f7e2798ab78c25440b40de4899a83 6. 2. 2015
6 wzrdlu2o0v 4115e6a74eb447895a1febc1234cb02326a9db0b 6. 2. 2015
7 401nd5xv80 a91ab8822be0d9fd6ed0f27d4d47533399ee1b2f 6. 2. 2015
8 qeba0t2ovv 5b1d6ec963f6d0024b40d96f2d2f3951fb69b694 6. 2. 2015
9 el25id2emd 47a721370eb86bba47acdf6234cf7e19aebbcd2b 6. 2. 2015
10 vmkppicf1z e28bdbe4cfb8123527b12baad31b6c26167907a9 6. 2. 2015
( Items: 1 - 10 from 200 )

Show me the code of this datagrid

public function createComponentGroupActionsGrid($name)
{
	/**
	 * @var Ublaboo\DataGrid\DataGrid
	 */
	$grid = new DataGrid($this, $name);

	$grid->setDataSource($this->ndb->table('ublaboo_example'));

	/**
	 * Columns
	 */
	$grid->addColumnNumber('id', 'Id')
		->setAlign('left')
		->setSortable();

	$grid->addColumnText('name', 'Name')
		->setSortable();

	$grid->addColumnText('random', 'sha1(name)')
		->setRenderer(function($item) {
			return sha1($item->name);
		});

	$grid->addColumnDateTime('inserted', 'Inserted');

	/**
	 * Group action
	 */
	$grid->addGroupAction('Change order status', $this->group_statuses)->onSelect[] = [$this, 'groupChangeStatus'];

	$grid->addGroupAction('Send', [
		'john'  => 'John',
		'joe'   => 'Joe',
		'frank' => 'Frank',
	])->onSelect[] = [$this, 'groupSend'];

	$grid->addGroupTextAction('Add note')->onSelect[] = [$this, 'addNote'];

	$grid->addGroupAction('Delete')->onSelect[] = [$this, 'deleteMany'];
}

Group action

Api

One level

If you need to do some operations with multiple rows, there are group actions. There are one or two level group actions. One level:

$grid->addGroupAction('Delete examples')->onSelect[] = [$this, 'deleteExamples'];
$grid->addGroupAction('Something alse')->onSelect[] = [$this, 'doSomethingElse'];

This will create one select box (['Delete examples', 'Something alse']) and submit button. If you submit that form, your handler will be called. It will be called via ajax.

This is how your handler can look like:

public function deleteExamples(array $ids)
{
	// Your code...

	if ($this->isAjax()) {
		$this['groupActionsGrid']->reload();
	} else {
		$this->redirect('this');
	}
}

Two level

There is also the two-level possibility of group action:

$grid->addGroupAction('Change order status', [
	1 => 'Received',
	2 => 'Ready',
	3 => 'Processing',
	4 => 'Sent',
	5 => 'Storno'
])->onSelect[] = [$this, 'groupChangeStatus'];

$grid->addGroupAction('Send', [
	'john'  => 'John',
	'joe'   => 'Joe',
	'frank' => 'Franta',
])->onSelect[] = [$this, 'groupSend'];

And some example handler:

public function groupChangeStatus(array $ids, $status)
{
	$this->flashMessage(
		sprintf("Status of items with id: [%s] was changed to: [$status]", implode($ids, ',')),
		'success'
	);

	$this->exampleRepository->updateStatus($ids, $status);

	if ($this->isAjax()) {
		$this->redrawControl('flashes');
		$this['groupActionsGrid']->reload();
	} else {
		$this->redirect('this');
	}
}

Text input

Group action can also containe a text input instad of select (As show in example above - option called "Add note"). Example code:

$grid->addGroupTextAction('Add note')
	->onSelect[] = [$this, 'addNote'];

And the ::addNote() method:

public function addNote(array $ids, $value)
{
	$this->flashMessage(
		sprintf('Note [%s] was added to items with ID: [%s]', $value, implode($ids, ',')),
		'success'
	);

	if ($this->isAjax()) {
		$this->redrawControl('flashes');
		$this['groupActionsGrid']->reload();
	} else {
		$this->redirect('this');
	}
}

Textarea

User may also use a textarea:

$grid->addGroupTextareaAction('aaaa');

Attributes, classes

All group action inputs have optional class or other attributes:

$grid->addGroupTextareaAction('aaaa')
	->setAttribute('rows', 10)
	->setClass('fooo');

Happy inputs

DataGrid uses tiny library happy for those nice checkboxes. You can disable them:

$grid->useHappyComponents(FALSE);
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tím souhlasíte. V pořádku Další informace