Id Name Link Status Action
489 3D Amish Solid
492 8-Bit Paintball Fiesta
184 8-Bit WWE World
582 A Boy and His Dog Strikes Again
874 Adorable Addax
645 Adorable Anteater
142 Adventurous Aardvark
635 Adventurous Addax
236 Adventurous Albatross
803 Adventurous Angelfish
608 Adventurous Armadillo
655 Adventurous Armadillo
365 Aero Jetski Assault
748 Aero Outlaw of Mystery
242 Aero Shopping Unit
638 Aggressive Alpaca
28 Aggressive Angelfish
165 Aggressive Antelope
627 Agreeable Alligator
338 Agreeable Ant
( Items: 1 - 20 from 1000 )
  See the code below 👇 or see GitHub
public function createComponentGrid(): DataGrid
{
	$grid = new DataGrid();

	$grid->setDataSource($this->dibiConnection->select('*')->from('users'));

	$grid->setItemsPerPageList([20, 50, 100]);

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

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

	$grid->addColumnLink('link', 'Link', 'this#demo', 'name', ['id', 'surname' => 'name'])
		->setEditableValueCallback(
			function (Row $row) {
				return $row['name'];
			}
		)
		->setEditableCallback(function ($id, $value): string {
			$this->flashMessage(sprintf('Id: %s, new value: %s', $id, $value));
			$this->redrawControl('flashes');

			$link = Html::el('a')
				->href($this->link('this#demo', ['id' => $id]))
				->setText($value);

			return (string) $link;
		})->addCellAttributes(['class' => 'text-center']);

	$grid->addColumnStatus('status', 'Status');

	$inlineEdit = $grid->addInlineEdit();

	$inlineEdit->onControlAdd[] = function ($container): void {
			$container->addText('name', '')
				->setRequired('aaa');
			$container->addText('birth_date', '');
			$container->addText('link', '');
			$container->addSelect('status', '', [
				'active' => 'Active',
				'inactive' => 'Inactive',
				'deleted' => 'Deleted',
			]);
	};

	$inlineEdit->onSetDefaults[] = function (Container $container, Row $row): void {
		$container->setDefaults([
			'id' => $row['id'],
			'name' => $row['name'],
			'birth_date' => $row['birth_date']->format('j. n. Y'),
			'link' => $row['name'],
			'status' => $row['status'],
		]);
	};

	$inlineEdit->onSubmit[] = function ($id, $values): void {
		$this->flashMessage('Record was updated! (not really)', 'success');
		$this->redrawControl('flashes');
	};

	$inlineEdit->setShowNonEditingColumns();

	return $grid;
}