CGridview 自定义字段可排序 [英] CGridview custom field sortable
本文介绍了CGridview 自定义字段可排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 yii Cgridview 中创建了自定义字段,但如何使其可排序.自定义字段值来自模型中的函数.我想让这个字段可排序?有人可以帮我吗?
I had created with custom field in yii Cgridview but how to make that sortable. The custom field value is from a function in the model. I want to make this field sortable? Can someone help me?
推荐答案
在你的模型的 search
函数中,其中 customField
是你的字段的名称:>
In the search
function of your model, where customField
is the name of your field:
// ...other criteria...
$criteria->compare('customField',$this->customField);
$sort = new CSort();
$sort->attributes = array(
'customField'=>array(
'asc'=>'customField ASC',
'desc'=>'customField DESC',
),
'*', // this adds all of the other columns as sortable
);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>$sort,
));
您可能还需要更新模型中的 rules
和 attributeLabels
以反映新的自定义字段.
You may also need to update rules
and attributeLabels
in your model to reflect the new custom field.
这篇关于CGridview 自定义字段可排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文