1

在此处输入图像描述

这是我的网格视图。当我单击“电子邮件”标题时,标题旁边有一个箭头。但是gridview不会重新加载来对数据进行排序。
那么,什么是问题?我怎样才能找到它?
谢谢...

==================================================== =====

这是我的看法:

<?php $this->widget('zii.widgets.grid.CGridView', array(

            'id' => 'users-grid',

            'dataProvider' => $model->search(),
            'afterAjaxUpdate' => 'function(id, data) { var regex = data.match("data-counter=\"(.*)\""); $("#countUser").text(regex[1]); }',
            'filter' => $model,
            'template'=>'{items}<div class="nav-controller">{pager}</div>',
            'columns' => array(
                array(
                    'class' => 'CCheckBoxColumn',
                    'selectableRows' => '2',
                ),
                array(
                    'htmlOptions' => array('width'=>10),
                    'header' => 'No.',
                    'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
                ),
                array(
                    'name' => 'full_name',
                    'value' => '$data->first_name . \' \' . $data->last_name',
                ),
                'email',
                array(

                    'name' => 'gender',

                    'value' => '($data->gender == 1) ? Yii::t(\'app\', \'Male\') : Yii::t(\'app\', \'Female\')',

                    'filter' => array('1' => Yii::t('app', 'Male'), '0' => Yii::t('app', 'Female')),

                ),
                array(
                    'name' => 'birthday',
                    'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'model'=>$model, 
                        'attribute'=>'birthday', 
                        'language' => 'en',
                        'i18nScriptFile' => 'jquery.ui.datepicker-ja.js', // (#2)
                        'htmlOptions' => array(
                            'id' => 'datepicker_for_birthday',
                            'size' => '10',
                        ),
                        'defaultOptions' => array(  // (#3)
                            'showOn' => 'focus', 
                            'dateFormat' => 'yy-mm-dd',
                            'showOtherMonths' => true,
                            'selectOtherMonths' => true,
                            'changeMonth' => true,
                            'changeYear' => true,
                            'showButtonPanel' => true,
                        )
                    ), 
                    true), // (#4)
                ),
                'home_town',

                array(
                    'header' => 'Action',
                    'class' => 'CButtonColumn',
                ),

            ),

        )); 

        ?>

这是我的控制器:

$model = new Users('search');

        $model->unsetAttributes();

        $this->render('index', array(

            'model' => $model,


        ));

这是我的搜索代码:

public function search() {

        $criteria = new CDbCriteria;
        $criteria->compare('id', $this->id);
        $criteria->compare('first_name', $this->first_name, true);
        $criteria->compare('last_name', $this->last_name, true);
        $criteria->compare('CONCAT(first_name, \' \', last_name)', $this->full_name, true);
        $criteria->compare('username', $this->username, true);
    $criteria->compare('email', $this->email, true);    
        $criteria->compare('avatar', $this->avatar, true);
        $criteria->compare('home_town', $this->home_town, true);
        $criteria->compare('birthday', $this->birthday, true);
        $criteria->compare('gender', $this->gender);
        $criteria->compare('about_me', $this->about_me, true);
        $criteria->compare('password', $this->password, true);
        $criteria->compare('log_as', $this->log_as);
        $criteria->compare('token', $this->token, true);
        $criteria->compare('token_device', $this->token_device, true);
        $criteria->compare('notification_setting', $this->notification_setting, true);
        $criteria->compare('total_streams', $this->total_streams);
        $criteria->compare('total_punches', $this->total_punches);
        $criteria->compare('total_likes', $this->total_likes);
        $criteria->compare('status', $this->status);
        $criteria->compare('role_id', $this->role_id);
        $criteria->compare('long', $this->long);
        $criteria->compare('lat', $this->lat);
        $criteria->compare('social_id', $this->social_id);
        $criteria->compare('created_at', $this->created_at, true);
        $criteria->compare('updated_at', $this->updated_at, true);
        $criteria->addSearchCondition('concat(first_name, " ", last_name)', $this->full_name); 
        $criteria->addCondition(array('condition'=>'role_id = 0'));
        ///$criteria->condition = "role_id != 1";
        $criteria->order = 'username';


        $sort = new CSort();
        $sort->attributes = array(
            'full_name'=>array(
                'asc'=>'first_name ASC',
                'desc'=>'first_name DESC',
            ),
            '*', // this adds all of the other columns as sortable
        );

        return new CActiveDataProvider($this, array(

            'criteria' => $criteria,

            'sort' => $sort,

        ));

    }
4

1 回答 1

10

您的问题似乎是搜索功能中的 $criteria->order = 'username' 行。这表明结果应该如何排序。

如果你把它更新为 $criteria->order = Yii::app()->request->getParam('sort'); (可能有一些验证和默认值“用户名”)那么你应该没问题。

于 2012-11-26T08:35:03.763 回答