Skip to content

Instantly share code, notes, and snippets.

@davidkudera
Created July 23, 2015 10:43
Show Gist options
  • Save davidkudera/82ed690ece35c5bed0a4 to your computer and use it in GitHub Desktop.
Save davidkudera/82ed690ece35c5bed0a4 to your computer and use it in GitHub Desktop.
No-Grid
{block content}
<h1>NoGrid</h1>
<div n:no-grid="noGridArray">
<ul>
<li n:no-grid-views-as="$view">
<a href="{$view->link}">{$view->title}</a>
</li>
</ul>
<table>
<thead>
<tr>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr n:no-grid-data-as="$line">
<td>{$line[num]}</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Display {$noGrid->getCount()} items from {$noGrid->getTotalCount()}</th>
</tr>
<tr>
<td>{control noGridArray:paginator}</td>
</tr>
</tfoot>
</table>
</div>
{/block}
<?php
namespace Carrooi\NetteSandbox\Presenters;
use Carrooi\NetteSandbox\Model\Books;
use Carrooi\NoGrid\DataSource\ArrayDataSource;
use Nette\Application\UI\Presenter;
/**
*
* @author David Kudera <[email protected]>
*/
class NoGridPresenter extends Presenter
{
/** @var \Carrooi\NetteSandbox\Model\Books\BooksFacade @inject */
public $books;
/** @var \Carrooi\NoGrid\INoGridFactory @inject */
public $gridFactory;
/**
* @return \Carrooi\NoGrid\NoGrid
*/
protected function createComponentNoGridArray()
{
$data = [];
for ($i = 0; $i < 50; $i++) {
$data[] = [
'num' => $i,
];
}
$dataSource = new ArrayDataSource($data);
$grid = $this->gridFactory->create($dataSource);
$grid->addView('1', '0 - 10', function(array &$data) {
$data = array_slice($data, 0, 10);
});
$grid->addView('2', '10 - 20', function(array &$data) {
$data = array_slice($data, 10, 10);
});
$grid->addView('3', '20 - 30', function(array &$data) {
$data = array_slice($data, 20, 10);
});
$grid->addView('4', '30 - 40', function(array &$data) {
$data = array_slice($data, 30, 10);
});
$grid->addView('5', '40 - 50', function(array &$data) {
$data = array_slice($data, 40, 10);
});
return $grid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment