2012-09-05 63 views
1

yii cactivedataprovider默認排序是指定的,但前臺使用AJAX排序無效。使用sortableattributes 排序是無效yii cactivedataprovider默認排序是指定的,但前臺使用AJAX排序無效

public function actionIndex() 
{ 
    // renders the view file 'protected/views/site/index.php' 
    // using the default layout 'protected/views/layouts/main.php' 
    $article = new CActiveDataProvider('article',array(
     'criteria'=>array(
      'order'=>'id DESC', 
     ), 
     'pagination'=>array(
      'pageSize'=>15, 
     ), 

    )); 
    $this->render('index',array('article'=>$article)); 
} 

$this->widget('bootstrap.widgets.TbListView', array(
'dataProvider'=>$article, 
'itemView'=>'_list', // refers to the partial view named '_post' 
'template'=>'{sorter}{items}{pager}{summary}', 
'sortableAttributes' => array(
    'id', 
    'date' 
) 

回答

7

默認順序必須被指定爲CActiveDataProvider::sortdefaultOrder財產。

所以修改代碼爲

$article = new CActiveDataProvider('article',array(
     'sort'=>array(
      'defaultOrder'=>'id DESC', 
     ), 
     'pagination'=>array(
      'pageSize'=>15, 
     ), 
+1

謝謝你,我按照你的問題的解決方案 – user1295679