|||
没那个功夫仔细阅读yii的文档,赶鸭子上架般匆匆用它做了个网站,默认的功能里有些要改,费了老大子劲解决了一些,赶紧写下来。
有一列数据A列既包含数字也包含字符串,老板说排序的时候只对数字排,字符串的都不要显示在前头,也就是说排序的时候忽略所有字符串。找了半天终于试出了一个可行的办法。在数据库中增加一列B,标出A列对应的表格是number还是character,然后在protected/models/对应model的php页面,改写public function search()函数,
public function search()
{
// Warning: Please modify thefollowing code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('expname',$this->expname,true);
$criteria->compare('strain',$this->strain,true);
$criteria->compare('mkgene',$this->mkgene,true);
$criteria->compare('kogene',$this->kogene,true);
$criteria->compare('penetrance',$this->penetrance,true);
$criteria->compare('cellcount',$this->cellcount);
$criteria->compare('endtimepoint',$this->endtimepoint,true);
$criteria->compare('comments',$this->comments,true);
$sort = new CSort();
$sort->defaultOrder = 'pencompDESC, CAST(penetrance AS UNSIGNED) ASC';
$sort->attributes = array(
'expname' =>'expname',
'strain' => 'strain',
'mkgene' => 'mkgene',
'kogene' => 'kogene',
//'penetrance' =>'penetrance',
'cellcount' =>'cellcount',
'endtimepoint' =>'endtimepoint',
'coord' => 'coord',
'penetrance'=>array(
'asc'=>'pencomp desc, CAST(penetrance AS UNSIGNED) ASC',
'desc'=>'pencomp desc, CAST(penetrance AS UNSIGNED) DESC',
),
);
return newCActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>$sort,
'pagination' =>array('pageSize' => 20,),
));
}
主要就是设置了B列(pencomp)永远按照降序排列,而A列(penetrance)数字部分的排序则加了CAST(penetrance AS UNSIGNED)。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 08:46
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社