public function columnOrder(){
return array(
'1'=>'Schulung',
'2'=>'Termin',
'3'=>'Anmeldungen'
);
}
//and in search function:
$sort = new CSort();
switch ($this->order){
case '1':
$sort->defaultOrder=array('sch_Name'=>CSort::SORT_ASC);
break;
case '2':
$sort->defaultOrder=array('dAnfang'=>CSort::SORT_ASC);
break;
case '3':
$sort->defaultOrder=array('registered'=>CSort::SORT_ASC);
default:
$sort->defaultOrder=array('cSchulungsTerminID'=>CSort::SORT_DESC);
}
...
...
...
For all the cases it works fine (when user selects from dropdownlist, sorting is done accordingly) except "case 3".
Where ‘registered’ is a count column (like in the wiki)
$registered_sql="(select count(cTeilnehmerID) from buchung b where b.cSchulungsTerminID=t.cSchulungsTerminID)";
$criteria->select=array(
'*',
$registered_sql.' as registered'
);
$criteria->compare($registered_sql,$this->registered);
Does case 1 or case 2 work fine AFTER you have sorted the grid by clicking on a header cell?
Doesn’t case 3 work BEFORE you sort the grid by clicking on a header cell?
Try disabling the sorting by the header cells by specifying $sort->attributes = array('');, and see what will happen.
I think the defaultOrder will not take effect when a sorting parameter (e.g. "sort=sch_Name.desc") is already in the query string. After you have sorted the grid by clicking on a cell in the header row, such a sorting parameter will override the default order.
The following may work, even with the default sorting functionality of the grid being enabled:
switch ($this->order){
case '1':
$_GET['sort'] = 'sch_Name';
break;
case '2':
$_GET['sort'] = 'dAnfang';
break;
case '3':
$_GET['sort'] = 'registered';
break;
default:
$_GET['sort'] = 'cSchulungsTerminID.desc';
break;
}
Or, in the view, you may create a plain dropdown (without the corresponding model) that will send a sorting parameter: