Permalink
Browse files

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

  • Loading branch information...
1 parent f0ee6c7 commit d10b0ae93e896354a271307dab76aec804ebb2d2 defacer committed Jun 20, 2005
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/tablelib.php
View
11 lib/tablelib.php
@@ -30,6 +30,8 @@ class flexible_table {
var $pagesize = 30;
var $currpage = 0;
var $totalrows = 0;
+ var $sort_default_column = NULL;
+ var $sort_default_order = SORT_ASC;
function flexible_table($uniqueid) {
$this->uniqueid = $uniqueid;
@@ -43,8 +45,10 @@ function flexible_table($uniqueid) {
);
}
- function sortable($bool) {
+ function sortable($bool, $defaultcolumn = NULL, $defaultorder = SORT_ASC) {
$this->is_sortable = $bool;
+ $this->sort_default_column = $defaultcolumn;
+ $this->sort_default_order = $defaultorder;
}
function collapsible($bool) {
@@ -222,6 +226,11 @@ function setup() {
}
}
+ // If we didn't sort just now, then use the default sort order if one is defined and the column exists
+ if(empty($this->sess->sortby) && !empty($this->sort_default_column) && isset($this->columns[$this->sort_default_column])) {
+ $this->sess->sortby = array ($this->sort_default_column => ($this->sort_default_order == SORT_DESC ? SORT_DESC : SORT_ASC));
+ }
+
if(isset($_GET[$this->request[TABLE_VAR_ILAST]])) {
if(empty($_GET[$this->request[TABLE_VAR_ILAST]]) || is_numeric(strpos(get_string('alphabet'), $_GET[$this->request[TABLE_VAR_ILAST]]))) {
$this->sess->i_last = $_GET[$this->request[TABLE_VAR_ILAST]];

0 comments on commit d10b0ae

Please sign in to comment.