Skip to content

Instantly share code, notes, and snippets.

@juzna
Created December 28, 2011 17:43
Show Gist options
  • Select an option

  • Save juzna/1528839 to your computer and use it in GitHub Desktop.

Select an option

Save juzna/1528839 to your computer and use it in GitHub Desktop.
RFC: how to DataGrid
Intro: Need to display tables of content, they need to be dynamic (pagable, sortable, filterable), how to solve it?
-------------------------------------------
1st - static table
<table>
<thead>
<tr>
<th>#</th>
<th>Published</th>
<th>Title</th>
<th>Author</th>
</tr>
</thead>
<tbody>
<tr n:foreach="$articles as $article">
<td>{$article->id}</td>
<td>{$article->published|date}</td>
<td>{$article->title}</td>
<td n:inner-if="$article->author"><a n:href=":Security:Backend:user, $article->author->id">{$article->author}</a></td>
<td><a n:href="edit, $article->id">edit</a> <a n:href="delete, $article->id">delete</a></td>
</tr>
</tbody>
</table>
-------------------------------------------
2nd - PHP code
{control usersTable}
<?php
$grid = new \Kdyby\Components\Grinder\Grid($model);
$grid->addCheckColumn('select');
$grid->addColumn('title', 'Title');
$grid->addColumn('published', 'Published');
$grid->addColumn('author', 'Author')->addFilter(function($value) { // This get's crazy!
if(!$value) return;
$a = \Nette\Utils\Html::el('a');
$a->href = $this->link(":Security:Backend:user", $value->id);
$a->setText($value->displayName);
return $a;
});
return $grid;
?>
-------------------------------------------
3rd - IDEA: dynamic using macros (BEST)
{grid $articles as $article}
{column id "#" /}
{column published "Published", editable /}
{column title "Title", editable /}
{column author "Author", sortBy => 'article.author.name', editable => , require => User:modify }
<a n:if="$article->author" n:href=":Security:Backend:user, $article->author->id">{$article->author}</a>
{/column}
{column actions "Actions", sortBy => null}
<a n:href="edit, $article->id">edit</a
<a n:href="delete, $article->id">delete</a>
{/column}
{/grid}
-------------------------------------------
4th - IDEA: attribute-macros (seems weird)
<table n:model="$articles as $article">
<td n:title="#">{$article->id}</td>
<td n:title="Published">{$article->published|date}</td>
<td n:title="Title">{$article->title}</td>
<td n:title="Author" n:inner-if="$article->author">
<a n:href=":Security:Backend:user, $article->author->id">{$article->author}</a>
</td>
<td n:title="Actions">
<a n:href="edit, $article->id">edit</a>
<a n:href="delete, $article->id">delete</a>
</td>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment