Permalink
Browse files

fix quicksearch and sorting

  • Loading branch information...
1 parent 94ba080 commit 150960d45731092736a8ac5b11079686a947d12d @romaninsh romaninsh committed Apr 15, 2011
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/Grid.php
View
@@ -132,6 +132,7 @@ function addButton($label,$name=null,$return_button=false){
}
function addQuickSearch($fields,$class='QuickSearch'){
return $this->add($class,null,'quick_search')
+ ->useGrid($this)
->useFields($fields);
}
function makeSortable($db_sort=null){
@@ -441,7 +442,7 @@ function setSource($table,$db_fields=null){
$this->dq->calc_found_rows();
return $this;
}
- function execQuery(){
+ function processSorting(){
if($this->sortby){
$desc=false;
$order=$this->sortby_db;
@@ -451,6 +452,9 @@ function execQuery(){
}
if($order)$this->dq->order($order,$desc);
}
+ }
+ function execQuery(){
+ $this->processSorting();
return parent::execQuery();
}
function setTemplate($template){
@@ -579,6 +583,7 @@ function formatRow(){
$formatters = explode(',',$column['type']);
foreach($formatters as $formatter){
+ if(!$formatter)continue;
if(method_exists($this,$m="format_".$formatter)){
$this->$m($tmp,$column);
}else throw new BaseException("Grid does not know how to format type: ".$formatter);
@@ -836,5 +841,17 @@ function addFormatter($field,$formatter){
}
$this->columns[$field]['type'].=','.$formatter;
if(method_exists($this,$m='init_'.$formatter))$this->$m($field);
+ return $this;
+ }
+ function setFormatter($field,$formatter){
+ /*
+ * replace current formatter for field
+ */
+ if(!isset($this->columns[$field])){
+ throw new BaseException('Cannot format nonexistant field '.$field);
+ }
+ $this->columns[$field]['type']=$formatter;
+ if(method_exists($this,$m='init_'.$formatter))$this->$m($field);
+ return $this;
}
}

0 comments on commit 150960d

Please sign in to comment.