Tip: Note that $limit and $offset parameters are appended to the dataLoader callback.
Tip: U can use [Ctrl] + arrow left/right to turn pages (make sure you've clicked inside the grid before to make it focused)
Name Surname Country
Aaliyah Storey ca
Aaya Weerdenburg it
Abbey Tunn fi
Abe Sneep fi
Abigail McKay fi
Adaora Eluemuno gb
Adaora Ikechukwu es
Adelbert Dávid pl
Adelheid Sørensen se
Adina Wallin gb
Admir Sagadin at
Agi Miklós se

Code

# PaginationGrid.php


class PaginationGrid extends BaseGrid
{

	/** @return void */
	protected function build()
	{
		parent::build();

		$this->setPrimaryKey('id');
		$this->addColumn('firstname', 'Name')->setSortable();
		$this->addColumn('surname', 'Surname')->setSortable();
		$this->addColumn('country_code', 'Country')->setSortable();

		$this->setPagination(12, [$this, 'userCounter']);
		$this->setDataLoader([$this, 'dataLoader']);
	}


	/**
	 * @param  PaginationGrid $grid
	 * @param  array $filters
	 * @return Nette\Database\Table\Selection
	 */
	public function userCounter(PaginationGrid $grid, array $filters)
	{
		return $this->database->table('user')->count('*');
	}


	/**
	 * @param  PaginationGrid $grid
	 * @param  array $filters
	 * @param  array $order
	 * @param  int $limit
	 * @param  int $offset
	 * @return Nette\Database\Table\Selection
	 */
	public function dataLoader(PaginationGrid $grid, array $filters, array $order, $limit, $offset)
	{
		$users = $this->database->table('user');

		// sorting
		foreach ($order as $column => $dir) {
			$users->order($column . ($dir === TwiGrid\Components\Column::DESC ? ' DESC' : ''));
		}

		// pagination
		$users->limit($limit, $offset);

		return $users;
	}

}
	

# BaseGrid.php


use Nette\Http\Session as NSession;
use Nette\Database\Context as NdbContext;


abstract class BaseGrid extends TwiGrid\DataGrid
{

	/** @var NdbContext */
	protected $database;


	/**
	 * @param  NSession $session
	 * @param  NdbContext $database
	 */
	public function __construct(NSession $session, NdbContext $database)
	{
		parent::__construct($session);
		$this->database = $database;
	}


	/** @return void */
	protected function build()
	{
		parent::build();
		$this->setRecordVariable('user');
	}

}