Name
Name2
Id
Status
6r0xliyalt
ozl4gy9udu
9i20xsrese
yk95ak88ra
2loxs05egs
  See the code below 👇 or see GitHub
public function createComponentGrid(): DataGrid
{
	$grid = new DataGrid();

	$join = $this->dibiConnection->select('COUNT(id) AS count, parent_category_id')
		->from('categories')
		->groupBy('parent_category_id');

	$fluent = $this->dibiConnection
		->select('c.*, c_b.count as has_children')
		->from('categories', 'c')
		->leftJoin($join, 'c_b')
		->on('c_b.parent_category_id = c.id')
		->where('c.parent_category_id IS NULL');

	$grid->setDataSource($fluent);

	$grid->setSortable();

	$grid->setTreeView([$this, 'getChildren'], 'has_children');

	$grid->addColumnText('name', 'Name');
	$grid->addColumnText('name2', 'Name2', 'name');
	$grid->addColumnText('id', 'Id')
		->setAlign('center');

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

	$columnStatus
		->addOption('active', 'Active')
		->endOption()
		->addOption('inactive', 'Inactive')
		->setClass('btn-warning')
		->endOption()
		->addOption('deleted', 'Deleted')
		->setClass('btn-danger')
		->endOption()
		->setSortable();
	$columnStatus->onChange[] = [$this, 'changeStatus'];

	$grid->addAction('edit', 'Edit', 'edit!')
		->setIcon('pencil pencil-alt')
		->setClass('btn btn-xs btn-default btn-secondary ajax')
		->setTitle('Edit');

	$grid->addAction('delete', '', 'delete!')
		->setIcon('trash')
		->setTitle('Delete')
		->setClass('btn btn-xs btn-danger ajax')
		->setConfirmation(
			new StringConfirmation('Do you really want to delete example %s?', 'name')
		);

	return $grid;
}