Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Augment tablelib so that it can accept a default sort order.

  • Loading branch information...
commit d10b0ae93e896354a271307dab76aec804ebb2d2 1 parent f0ee6c7
authored June 20, 2005

Showing 1 changed file with 10 additions and 1 deletion. Show diff stats Hide diff stats

  1. 11  lib/tablelib.php
11  lib/tablelib.php
@@ -30,6 +30,8 @@ class flexible_table {
30 30
     var $pagesize    = 30;
31 31
     var $currpage    = 0;
32 32
     var $totalrows   = 0;
  33
+    var $sort_default_column = NULL;
  34
+    var $sort_default_order  = SORT_ASC;
33 35
 
34 36
     function flexible_table($uniqueid) {
35 37
         $this->uniqueid = $uniqueid;
@@ -43,8 +45,10 @@ function flexible_table($uniqueid) {
43 45
         );
44 46
     }
45 47
 
46  
-    function sortable($bool) {
  48
+    function sortable($bool, $defaultcolumn = NULL, $defaultorder = SORT_ASC) {
47 49
         $this->is_sortable = $bool;
  50
+        $this->sort_default_column = $defaultcolumn;
  51
+        $this->sort_default_order  = $defaultorder;
48 52
     }
49 53
 
50 54
     function collapsible($bool) {
@@ -222,6 +226,11 @@ function setup() {
222 226
             }
223 227
         }
224 228
 
  229
+        // If we didn't sort just now, then use the default sort order if one is defined and the column exists
  230
+        if(empty($this->sess->sortby) && !empty($this->sort_default_column) && isset($this->columns[$this->sort_default_column])) {
  231
+            $this->sess->sortby = array ($this->sort_default_column => ($this->sort_default_order == SORT_DESC ? SORT_DESC : SORT_ASC));
  232
+        }
  233
+
225 234
         if(isset($_GET[$this->request[TABLE_VAR_ILAST]])) {
226 235
             if(empty($_GET[$this->request[TABLE_VAR_ILAST]]) || is_numeric(strpos(get_string('alphabet'), $_GET[$this->request[TABLE_VAR_ILAST]]))) {
227 236
                 $this->sess->i_last = $_GET[$this->request[TABLE_VAR_ILAST]];

0 notes on commit d10b0ae

Please sign in to comment.
Something went wrong with that request. Please try again.