tri automatique en cliquant sur l'entete de colonne des table editor : bug #484
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 3 Oct 2006 21:36:27 +0000 (21:36 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 3 Oct 2006 21:36:27 +0000 (21:36 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@944 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/pltableeditor.php
templates/table-editor.tpl

index 7d435a5..58894d6 100644 (file)
@@ -36,6 +36,8 @@ class PLTableEditor {
     var $vars;
     // number of displayed fields
     var $nbfields;
+    // the field for sorting entries
+    var $sortfield;
     /* table editor for platal
      * $plname : the PLname of the page, ex: admin/payments
      * $table : the table to edit, ex: profile_medals
@@ -46,6 +48,7 @@ class PLTableEditor {
         $this->pl = $plname;
         $this->table = $table;
         $this->idfield = $idfield;
+        $this->sortfield = $idfield;
         $this->idfield_editable = $editid;
         $r = XDB::iterator("SHOW COLUMNS FROM $table");
         $this->vars = array();
@@ -185,6 +188,19 @@ class PLTableEditor {
                 $page->trig("Impossible de mette à jour.");
         }
         if ($list) {
+            // user can sort by field by clicking the title of the column
+            if ($action == 'sort' || $action == 'sortdesc') {
+                if (isset($this->vars[$id])) {
+                    // add this sort order after the others (chosen by dev)
+                    $this->add_sort_field($id, $action == 'sortdesc');
+                    // set as sortfield to reverse sort when clicking again
+                    if ($action == 'sort') {
+                        $this->sortfield = $id;
+                    } else {
+                        $this->sortfield = '';
+                    }
+                } 
+            }
             if (count($this->sort) > 0) {
                 $sort = 'ORDER BY ' . join($this->sort, ',');
             }
index 7226fc2..cfa08e9 100644 (file)
@@ -27,8 +27,8 @@
 
 <table class="bicol">
 <tr>
-  {foreach from=$t->vars item=myval}{if $myval.display}
-    <th>{$myval.desc}</th>
+  {foreach from=$t->vars item=myval key=myvar}{if $myval.display}
+    <th><a href='{$t->pl}/sort{if $t->sortfield eq $myvar}desc{/if}/{$myvar}'>{$myval.desc}</a></th>
   {/if}{/foreach}
   {if !$hideactions}
   <th>action</th>