Id Name Link Inserted Status Action
1 6r0xliyalt 6. 2. 2015 Offline
2 ozl4gy9udu 6. 2. 2015 Offline
3 9i20xsrese 6. 2. 2015 Standby
4 yk95ak88ra 6. 2. 2015 Standby
5 2loxs05egs 6. 2. 2015 Offline
6 wzrdlu2o0v 6. 2. 2015 Online
7 401nd5xv80 6. 2. 2015 Online
8 qeba0t2ovv 6. 2. 2015 Offline
9 el25id2emd 6. 2. 2015 Online
10 vmkppicf1z 6. 2. 2015 Online
( Items: 1 - 10 from 200 )

Show me the code of this datagrid

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

	$grid->setDataSource($this->db->select('*')->from('ublaboo_example'));

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

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

	$grid->addColumnText('name', 'Name')
		->setSortable()
		->setEditableCallback(function($id, $value) {
			$this->flashMessage("Id: $id, new value: $value");
			$this->redrawControl('flashes');
		})->addAttributes(['class' => 'text-center']);

	$grid->addColumnLink('link', 'Link', 'this#demo', 'name', ['id', 'surname' => 'name']);

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

	$grid->addColumnText('status', 'Status')
		->setReplacement([
			0 => 'Offline',
			1 => 'Online',
			2 => 'Standby'
		]);

	/**
	 * Some action
	 */
	$grid->addAction('delete', '', 'delete!')
		->setIcon('trash')
		->setTitle('Delete')
		->setClass('btn btn-xs btn-danger ajax')
		->setConfirm('Do you really want to delete example %s?', 'name');

	$grid->addInlineAdd()
		->setPositionTop()
		->onControlAdd[] = function($container) {
			$container->addText('id', '')->setAttribute('readonly');
			$container->addText('name', '');
			$container->addText('inserted', '');
			$container->addText('link', '');
		};

	$grid->getInlineAdd()->onSubmit[] = function($values) {
		/**
		 * Save new values
		 */
		$v='';foreach($values as $key=>$value){$v.="$key: $value, ";}$v=trim($v,', ');

		$this->flashMessage("Record with values [$v] was added! (not really)", 'success');

		$this->redrawControl('flashes');
		$this['addableGrid']->redrawControl();
	};
}

Inline adding

Since version 3.3.0 there is a "inline adding" available. Up above is a demo where you can try that out. Just hit the "plus" button, fill some inputs and save the container. Example implementation:

$grid->addInlineAdd()
	->onControlAdd[] = function($container) {
		$container->addText('id', '')->setAttribute('readonly');
		$container->addText('name', '');
		$container->addText('inserted', '');
		$container->addText('link', '');
	};

$p = $this;

$grid->getInlineAdd()->onSubmit[] = function($values) use ($p) {
	/**
	 * Save new values
	 */
	$v='';foreach($values as $key=>$value){$v.="$key: $value, ";}$v=trim($v,', ');

	$p->flashMessage("Record with values [$v] was added! (not really)", 'success');

	$p->redrawControl('flashes');
};

Position of new item row

As you can see, new item row is rendered at the bottom of the table. You may change that and make datagrid render the new item row on the top:

$grid->addInlineAdd()
	->setPositionTop(); // Or take it down again: ::setPositionTop(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