问题描述
我有很多型号和GridView的在我的项目,每一个模型都有 create_dttm
字段。
I have many models and gridviews in my project and every model has create_dttm
field.
我现在想,我怎么能覆盖类 CActiveDataProvider
,我会添加降序排序条件
I would like now that how can I override class CActiveDataProvider
where I'll add DESC Sort condition
即
'sort' => array(
'defaultOrder' => 'create_dttm DESC',
)
,这样它会工作为我所有的GridView的,而不是增加情况在每个GridView控件。
so that it'll work for all my gridviews instead of adding condition in each gridview.
例如:
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('name', $this->name, true);
$criteria->compare('age', $this->age);
$criteria->compare('create_dttm', $this->create_dttm, true);
$criteria->compare('update_dttm', $this->update_dttm, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 10,
),
'sort' => array(
'defaultOrder' => 'create_dttm DESC',
)
));
}
我该如何处理?
How can I deal with this?
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
我觉得最简单的方法是在每个模型添加排序变量。
I think the easy way is add the sort variable on each model.
否则,你可以使用这种方法,因为下面的链接,但如果你使用的方式,您需要更改名字。
or else you can using this method as below link, but if you using that's way you need change the name as well.
的
所以我的建议是,增加的排序上的每一个模型。
so my suggestion is, add the sort on each model.
这篇关于如何覆盖CActiveDataProvider法在默认情况下,在Yii中降序排列显示CGridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!