CGridview custom field sortable

此生再无相见时 提交于 2019-12-24 03:51:40

问题


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?


回答1:


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,
));

You may also need to update rules and attributeLabels in your model to reflect the new custom field.




回答2:


There is a detailed description about searching on custom fields at this URL:

Using standard filters in CGridView custom fields



来源:https://stackoverflow.com/questions/7633516/cgridview-custom-field-sortable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!