Yii 可排序属性 [英] Yii Sortable Attributes

查看:16
本文介绍了Yii 可排序属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下标签,但是当我将名字定义为可排序时,它不起作用(未将名字显示为可以单击并排序列表视图的链接).尽管如此,如果我的用户名工作正常.

I have the following talbes but when I define firstname as sortable it is not working (not showing firstname as link where I can click and sort the List View). Despite that if I user username is working just fine.

| User
| - userid
| - username

| Profile
| - userid
| - firstname
| - lastname

我在控制器中:

    $criteria->with=array(
        'profile',
    );
    $criteria->addCondition('status = 1 or status = 2 or status = 3');

    if($search) 
        $criteria->addCondition("firstname = '{$search}'");

    $dataProvider=new CActiveDataProvider('YumUser', array(
                'criteria' => $criteria, 
                'pagination'=>array(
                    'pageSize'=>50,
                    )));

在视图中:

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view', 
        'template' => '{summary} {sorter} {items} <div style="clear:both;"></div> {pager}',
    'sortableAttributes'=>array(
        'firstname',
    ),
));

推荐答案

这仅适用于 sort 属性(在这些情况下,您按另一个模型中的属性排序)

This only works if the sort property of the dataProvider is set explicitly (in these cases, where you're sorting by an attribute that is in another model)

试试这个

 $dataProvider =  new CActiveDataProvider('YumUser', array(
                'criteria' => $criteria, 
                'sort'=>array(
                    'attributes'=>array(
                         'firstname'=>array(
                              'asc'=>'firstname',
                              'desc'=>'firstname DESC',
                          ),
                     ),
                 ),
                'pagination'=>array(
                    'pageSize'=>50,
                    )));

这篇关于Yii 可排序属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆