Id Status Emojis (template) Birthday Age
One 👍 23. 2. 1982 42
Two 👍 2. 1. 1997 27
Trhee 🤪 21. 5. 1955 68
4 🤪 23. 5. 1964 59
5 🤪 23. 8. 1939 84
6 🤦‍♀️ 25. 9. 1985 38
7 👍 11. 3. 1974 50
8 👍 23. 5. 1946 77
9 🤦‍♀️ 20. 4. 1944 80
10 🤦‍♀️ 10. 4. 1981 43
11 🤦‍♀️ 19. 9. 1994 29
12 👍 19. 1. 1936 88
13 👍 27. 9. 1978 45
14 🤦‍♀️ 15. 12. 1977 46
15 🤦‍♀️ 3. 3. 1987 37
16 🤦‍♀️ 11. 2. 1945 79
17 🤪 8. 3. 1983 41
18 🤦‍♀️ 28. 4. 1931 92
19 🤦‍♀️ 27. 10. 1949 74
20 🤪 14. 8. 1941 82
Ids sum: 210 Avg Age: 60
( Items: 1 - 20 from 1000 )
  See the code below 👇 or see GitHub
public function createComponentGrid(): DataGrid
{
	$grid = new DataGrid();

	$grid->setDefaultSort(['id' => 'ASC']);

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

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

	$grid->addColumnText('id', 'Id')
		->setReplacement([
			1 => 'One',
			2 => 'Two',
			3 => 'Trhee',
		])
		->setSortable();

	$grid->addColumnLink('email', 'E-mail', 'this')
		->setSortable();

	$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->addColumnText('emojis', 'Emojis (template)')
		->setTemplate(__DIR__ . '/../templates/Columns/grid/columnsEmojis.latte');

	$grid->addColumnDateTime('birth_date', 'Birthday')
		->setFormat('j. n. Y')
		->setSortable();

	$grid->addColumnNumber('age', 'Age')
		->setRenderer(function (Row $row): int {
			return $row['birth_date']->diff(new DateTime())->y;
		});

	$grid->setColumnsHideable();

	/*$grid->setColumnsSummary(['id'])
		->setRenderer(function(int $summary, string $column): string {
			return 'Summary renderer: ' . $summary . ' $';
		});*/

	$grid->addColumnCallback('status', function (ColumnStatus $column, Row $row): void {
		if ($row['id'] === 3) {
			$column->removeOption('active');
		}
	});

	$grid->addColumnCallback('email', function (ColumnLink $column, Row $row): void {
		if ($row['id'] === 3) {
			$column->setRenderer(function (): string {
				return '';
			});
		}
	});

	// $grid->addAggregationFunction('status', new FunctionSum('id'));

	$grid->setMultipleAggregationFunction(
		new class implements IMultipleAggregationFunction
		{

			/** @var int */
			private $idsSum = 0;

			/** @var float */
			private $avgAge = 0.0;

			public function getFilterDataType(): string
			{
				return IAggregationFunction::DATA_TYPE_PAGINATED;
			}

			/** @param mixed $dataSource */
			public function processDataSource($dataSource): void
			{
				if (!$dataSource instanceof Fluent) {
					throw new UnexpectedValueException();
				}

				$this->idsSum = (int) $dataSource->getConnection()
					->select('SUM([id])')
					->from($dataSource, '_')
					->fetchSingle();

				$this->avgAge = round((float) $dataSource->getConnection()
					->select('AVG(YEAR([birth_date]))')
					->from($dataSource, '_')
					->fetchSingle());
			}

			public function renderResult(string $key): string
			{
				if ($key === 'id') {
					return 'Ids sum: ' . $this->idsSum;
				}

				if ($key === 'age') {
					return 'Avg Age: ' . ((int) date('Y') - $this->avgAge);
				}

				return '';
			}

		}
	);

	return $grid;
}