【问题标题】:CGridview custom field sortableCGridview 自定义字段可排序
【发布时间】:2011-11-29 19:35:39
【问题描述】:

我在 yii Cgridview 中创建了自定义字段,但如何使该字段可排序。自定义字段值来自模型中的函数。我想让这个字段可排序? 有人可以帮我吗?

【问题讨论】:

  • 我们需要更多信息 - 您是否定义了自定义排序?您使用的是什么数据提供商?

标签: yii cgridview


【解决方案1】:

在您的模型的search 函数中,其中customField 是您的字段名称:

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

您可能还需要更新模型中的 rulesattributeLabels 以反映新的自定义字段。

【讨论】:

  • 您能否描述模型中的 rulesattributeLabels 需要哪些更新以反映新的自定义字段。请详细说明
【解决方案2】:

此网址有关于搜索自定义字段的详细说明:

Using standard filters in CGridView custom fields

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 2014-07-14
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多