new CArrayDataProvider($rawData, array(
'id'=>'user',
'sort'=>array(
'defaultOrder'=>'case when the_column is null then 1 else 0, the_column',
'user'=>array(
'asc'=>'case when the_column is null then 1 else 0, the_column',
'desc'=>'case when the_column is null then 0 else 1, the_column', //<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' /> I don't know about this part <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />
)
)
));
While CActiveDataProvider uses ‘ORDER’ clause to get the sorted data, CArrayDataProvider uses array_multisort() to sort the raw data. So I guess it’s not possible to use something like ‘case when … then … else …’ in the sorting conditions.
This is what I found some thing useful.Though it is not a better solution.
For CArrayDataProvider:
If column value is null, we are going to give a massive number
that is greater than maximum value in the column.
When page loads we are going to get the display in ascending order with null values at bottom.
When we click the sorter, we are going to get default order in the table or
descending order with null values at bottom.
public function search()
{
$criteria=new CDbCriteria;
.........................
.........................
$criteria->order="IFNULL(column_name,10000000) ASC";//some big value that is beyond the scope.
.................................................
................................................
$objects=AR::model()->findAll($criteria);
return new CArrayDataProvider($objects,array(
'sort'=>array('attributes'=>array('attributeName'=>array('desc'=>'column_name DESC')))
));
}
For CActiveDataProvider:
Here we can not apply the order beforehand in CDbCriteria.
public function search()
{
$criteria=new CDbCriteria;
.........................
.........................
/// $criteria->order="IFNULL(column_name,10000000) ASC"; This makes the sorter inactive.
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array('attributes'=>array('attributeName'=>array('asc'=>'IFNULL(column_name,10000000) ASC','desc'=>'column_name DESC')))
));
}