juzna

datagrid

Dec 28th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. Which seems to be the best way to display a table, which should be dynamic (like a datagrid/Grinder)?
  2.  
  3. --------------------
  4. 1st - static table (starting point)
  5.  
  6. <table>
  7.     <thead>
  8.     <tr>
  9.         <th>#</th>
  10.         <th>Published</th>
  11.         <th>Title</th>
  12.         <th>Author</th>
  13.     </tr>
  14.     </thead>
  15.     <tbody>
  16.     <tr n:foreach="$articles as $article">
  17.         <td>{$article->id}</td>
  18.         <td>{$article->published|date}</td>
  19.         <td>{$article->title}</td>
  20.         <td n:inner-if="$article->author"><a n:href=":Security:Backend:user, $article->author->id">{$article->author}</a></td>
  21.         <td><a n:href="edit, $article->id">edit</a>  <a n:href="delete, $article->id">delete</a></td>
  22.     </tr>
  23.     </tbody>
  24. </table>
  25.  
  26.  
  27.  
  28. -------------------------------------------
  29. 2nd - PHP code & Grinder
  30.  
  31. {control usersTable}
  32.  
  33. <?php
  34. $grid = new \Kdyby\Components\Grinder\Grid($model);
  35.  
  36. $grid->addCheckColumn('select');
  37. $grid->addColumn('title', 'Title');
  38. $grid->addColumn('published', 'Published');
  39. $grid->addColumn('author', 'Author')->addFilter(function($value) { // This get's crazy!
  40.     if(!$value) return;
  41.     $a = \Nette\Utils\Html::el('a');
  42.     $a->href = $this->link(":Security:Backend:user", $value->id);
  43.     $a->setText($value->displayName);
  44.    
  45.     return $a;
  46. });
  47.  
  48. return $grid;
  49. ?>
  50.  
  51.  
  52.  
  53.  
  54. -------------------------------------------
  55. 3rd - IDEA: dynamic using macros (BEST)
  56.  
  57. {grid $articles as $article}
  58.     {column id "#" /}
  59.     {column published "Published", editable /}
  60.     {column title "Title", editable /}
  61.     {column author "Author", sortBy => 'article.author.name', editable => , require => User:modify  }
  62.         <a n:if="$article->author" n:href=":Security:Backend:user, $article->author->id">{$article->author}</a>
  63.     {/column}
  64.     {column actions "Actions", sortBy => null}
  65.         <a n:href="edit, $article->id">edit</a
  66.         <a n:href="delete, $article->id">delete</a>
  67.     {/column}
  68. {/grid}
  69.  
  70.  
  71.  
  72. -------------------------------------------
  73. 4th - IDEA: attribute-macros (seems weird)
  74.  
  75. <table n:model="$articles as $article">
  76.     <td n:title="#">{$article->id}</td>
  77.     <td n:title="Published">{$article->published|date}</td>
  78.     <td n:title="Title">{$article->title}</td>
  79.     <td n:title="Author" n:inner-if="$article->author">
  80.         <a n:href=":Security:Backend:user, $article->author->id">{$article->author}</a>
  81.     </td>
  82.     <td n:title="Actions">
  83.         <a n:href="edit, $article->id">edit</a>
  84.         <a n:href="delete, $article->id">delete</a>
  85.     </td>
  86. </table>
Advertisement
Add Comment
Please, Sign In to add comment