Id Name Status Birthday Birthday 2 Age
-
-
1 Klikam na asd 23. 2. 1982 23. 2. 1982 42
2 aaaa 2. 1. 1997 2. 1. 1997 27
3 aaa 21. 5. 1955 21. 5. 1955 69
4 Difficult Deer 23. 5. 1964 23. 5. 1964 60
5 Underground Harpoon Gladiator 23. 8. 1939 23. 8. 1939 85
6 Anxious Alpacaaaa a aa 25. 9. 1985 25. 9. 1985 39
7 Misty Meerkat 11. 3. 1974 11. 3. 1974 50
8 Funky Chainsaw of Mysteryasd as da 23. 5. 1946 23. 5. 1946 78
9 Sid Meier Deer Hunter Hoedown 20. 4. 1944 20. 4. 1944 80
10 Terrible Karaoke of Mystery 10. 4. 1981 10. 4. 1981 43
11 Joyous Jaguara sda sd 19. 9. 1994 19. 9. 1994 30
12 Silly Sheepasdasd 19. 1. 1936 19. 1. 1936 88
13 Grumpy Gerenuk 27. 9. 1978 27. 9. 1978 46
14 Glorious Gaur 15. 12. 1977 15. 12. 1977 46
15 Xenophobic Xenomorph 3. 3. 1987 3. 3. 1987 37
16 Relieved Rhinoceros 11. 2. 1945 11. 2. 1945 79
17 Bad Buzzard 8. 3. 1983 8. 3. 1983 41
18 Dangerous Dolphin 28. 4. 1931 28. 4. 1931 93
19 Quaint Quoll 27. 10. 1949 27. 10. 1949 75
20 Thoughtless Turkey 14. 8. 1941 14. 8. 1941 83
( Items: 1 - 20 from 1020 )
  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], true);

	$grid->addColumnText('id', 'Id')
		->setFilterText()
		->setExactSearch();

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

	$grid->addColumnStatus('status', 'Status')
		->setFilterSelect([
			'' => 'All',
			'active' => 'Active',
			'inactive' => 'Inactive',
			'deleted' => 'Deleted',
		]);

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

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

	$grid->addColumnNumber('age', 'Age')
		->setRenderer(fn (Row $row): ?int => DateTime::fromSafe($row->asDateTime('birth_date'))?->diff(new DateTime())->y)
		->setFilterRange()
		->setCondition(function (Fluent $fluent, ArrayHash $values): void {
			if ((bool) $values['from']) {
				$fluent->where('(YEAR(CURDATE()) - YEAR(birth_date)) >= ?', $values['from']);
			}

			if ((bool) $values['to']) {
				$fluent->where('(YEAR(CURDATE()) - YEAR(birth_date)) <= ?', $values['to']);
			}
		});

	// $grid->setOuterFilterRendering();

	return $grid;
}