PHP code example of uestla / twigrid

1. Go to this page and download the library: Download uestla/twigrid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

uestla / twigrid example snippets


	// app/Grids/UsersGrid.php

	final class UsersGrid extends TwiGrid\DataGrid
	{
		private $database;

		public function __construct(Nette\Database\Explorer $database)
		{
			parent::__construct();

			$this->database = $database;
		}

		protected function build(): void
		{
			// TODO
		}
	}
	

	// app/Grids/UsersGrid.php

	final class UsersGrid extends TwiGrid\DataGrid
	{
		// ...

		protected function build(): void
		{
			$this->addColumn('firstname', 'Firstname');
			$this->addColumn('surname', 'Surname');
			$this->addColumn('streetaddress', 'Street address');
			$this->addColumn('city', 'City');
			$this->addColumn('country_code', 'Country');
		}
	}
	

	$this->setPrimaryKey('id');
	

	$this->setDataLoader(function () {
		return $this->database->table('user');
	});
	

	// app/Grids/UsersGridFactory.php

	interface UsersGridFactory
	{
		public function create(): UsersGrid;
	}
	

	// app/Presenters/HomepagePresenter.php

	class HomepagePresenter extends BasePresenter
	{
		/** @var \UsersGridFactory @inject */
		public $usersGridFactory;
	}
	

	// app/Presenters/HomepagePresenter.php

	protected function createComponentUsersGrid(): \UsersGrid
	{
		return $this->usersGridFactory->create();
	}
	

	// app/Grids/UsersGrid.php::build()

	$this->setTemplateFile(__DIR__ . '/UsersGrid.latte');