Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Which seems to be the best way to display a table, which should be dynamic (like a datagrid/Grinder)?
- --------------------
- 1st - static table (starting point)
- <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 & Grinder
- {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>
Advertisement
Add Comment
Please, Sign In to add comment