noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 239/323: Manage_Table : add sort on header co


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 239/323: Manage_Table : add sort on header column
Date: Wed, 14 Mar 2018 17:38:58 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit e66033d9b5512693b5d442c87367d3c54a7220b1
Author: Dany De Bontridder <address@hidden>
Date:   Fri Feb 23 20:38:25 2018 +0100

    Manage_Table : add sort on header column
---
 include/lib/manage_table_sql.class.php | 45 +++++++++++++++++++++++++++-------
 scenario/test_manage_table_sql.php     |  4 +--
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/include/lib/manage_table_sql.class.php 
b/include/lib/manage_table_sql.class.php
index 24daa4b..2d1b9f1 100644
--- a/include/lib/manage_table_sql.class.php
+++ b/include/lib/manage_table_sql.class.php
@@ -58,6 +58,7 @@
   @endcode
  * @see ManageTable.js
  * @see ajax_accounting.php
+ * @see sorttable.js
  * 
  */
 
@@ -78,7 +79,7 @@ class Manage_Table_SQL
     protected $aerror; //!< Array containing the error of the input data
     protected $col_sort; //!< when inserting, it is the column to sort,-1 to 
disable it and append only
     protected $a_info; //!< Array with the infotip
-
+    protected $sort_column; //!< javascript sort , if empty there is no js sort
     const UPDATABLE=1;
     const VISIBLE=2;
 
@@ -118,6 +119,8 @@ class Manage_Table_SQL
         $this->icon_mod="right";
         $this->icon_del="right";
         $this->col_sort=0;
+        // By default no js sort
+        $this->sort_column="";
     }
     /**
      * send the XML headers for the ajax call 
@@ -626,7 +629,14 @@ function check()
             }
         }
         echo _('Cherche')." ".HtmlInput::filter_table("tb".$this->object_name, 
$result, 1);
-        printf('<table class="result" id="tb%s">', $this->object_name);
+        
+        // Set a sort on a column if sort_column is not empty
+        if ( $this->sort_column =="")
+        {
+            printf('<table class="result" id="tb%s">', $this->object_name); 
+        } else {
+           printf('<table class="result sortable" id="tb%s">', 
$this->object_name);
+        }
         for ($i=0; $i<$nb; $i++)
         {
             if ($i==0)
@@ -659,31 +669,48 @@ function check()
 
         if ($this->can_update_row() && $this->icon_mod=="left")
         {
-            echo th("  ", 'style="width:40px"');
+            echo th("  ", 'style="width:40px"  class="sorttable_nosort"');
         }
         if ($this->can_delete_row() && $this->icon_del=="left")
         {
-            echo th(" ", 'style="width:40px"');
+            echo th(" ", 'style="width:40px"  class="sorttable_nosort"');
         }
         for ($i=0; $i<$nb; $i++)
         {
 
             $key=$this->a_order[$i];
-
+            $sorted="";
+            if ( $key == $this->sort_column) {
+                $sorted=' class="sorttable_sorted"';
+            }
             if ($this->get_property_visible($key)==true)
-                echo th("","",$this->a_label_displaid[$key]);
+                echo th("",$sorted,$this->a_label_displaid[$key]);
         }
         if ($this->can_update_row() && $this->icon_mod=="right")
         {
-            echo th("  ", 'style="width:40px"');
+            echo th("  ", 'style="width:40px"  class="sorttable_nosort"');
         }
         if ($this->can_delete_row() && $this->icon_del=="right")
         {
-            echo th(" ", 'style="width:40px"');
+            echo th(" ", 'style="width:40px"  class="sorttable_nosort" ');
         }
         echo "</tr>";
     }
-
+    /**
+     * set the column to sort by default
+     */
+    function set_sort_column($p_col)
+    {
+        $this->sort_column=$p_col;
+    }
+    /**
+     * return the column to sort
+     */
+    function get_sort_column()
+    {
+        return $this->sort_column;
+    }
+    
     /**
      * @brief set the id value of a data row and load from the db
      */
diff --git a/scenario/test_manage_table_sql.php 
b/scenario/test_manage_table_sql.php
index 6f813a7..b342606 100644
--- a/scenario/test_manage_table_sql.php
+++ b/scenario/test_manage_table_sql.php
@@ -51,7 +51,7 @@ $manage_table->set_col_label('pcm_val', "Poste");
 $manage_table->set_col_label('parent_accounting', "Dépend");
 $manage_table->set_col_label('pcm_lib', "Libellé");
 $manage_table->set_col_label('pcm_type', "Type de 
menu".Icon_Action::infobulle(33));
-
+$manage_table->set_sort_column("pcm_lib");
 // Change visible property
 function test_visible_update(Manage_Table_SQL 
$p_manage_table,$p_property,$p_visible,$p_update) {
     global $g_failed,$g_succeed;
@@ -75,11 +75,11 @@ test_visible_update($manage_table, "parent_accounting", 
FALSE, FALSE);
 test_visible_update($manage_table, "parent_accounting", FALSE, TRUE);
 test_visible_update($manage_table, "parent_accounting", TRUE, FALSE);
 test_visible_update($manage_table, "parent_accounting", TRUE, TRUE);
-
 echo "<h1>"."Icon MODIFY place"."</h1>";
 echo "<h2>"." Mod left"."</h2>";
 $manage_table->set_icon_mod("left");
 $manage_table->display_table("where pcm_val::text >= '400' order by 
pcm_val::text limit 10");
+return;
 
 echo "<h2>"." Mod right"."</h2>";
 $manage_table->set_icon_mod("right");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]