2012-11-26 4 views
1

enter image description hereyii cgridview 정렬 작동하지 않음

이것은 내 그리드보기입니다. '이메일'헤더를 클릭하면 헤더 옆에 화살표가 표시됩니다. 그러나 gridview는 데이터를 정렬하기 위해 다시로드하지 않습니다.
그래서 문제가 무엇입니까? 어떻게 찾을 수 있습니까?
감사 ...

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

$model = new Users('search'); 

     $model->unsetAttributes(); 

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

      'model' => $model, 


     )); 

이 내 검색 코드 :

이 내 컨트롤러

<?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', 
       ), 

      ), 

     )); 

     ?> 

: ===============

이 내이다

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, 

     )); 

    } 
+0

javascript afterAjaxUpdate에서 콘솔 오류가 발생하고 있습니까? –

+0

콘솔 오류가 없습니다. http : // localhost : 8016/index.php/admin/users/index/ajax/users-grid/sort/email.desc? ajax = users-grid –

+0

당신의'$ model-> search()'code – Sergey

답변

8

검색 기능에 문제가 $ criteria-> order = 'username'줄 인 것 같습니다. 결과를 정렬하는 방법을 나타내는 것입니다.

$ criteria-> order = Yii :: app() -> request-> getParam ('sort')로 업데이트하면; (일부 확인 및 'username'기본값) 아마 다음 괜찮을합니다.