2

yii cactivedataprovider 默认排序是指定的,但是前台使用AJAX排序是无效的。使用 sortableattributes 排序无效

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'
)
4

1 回答 1

10

默认顺序必须指定为 的defaultOrder属性CActiveDataProvider::sort

所以修改你的代码为

$article = new CActiveDataProvider('article',array(
        'sort'=>array(
            'defaultOrder'=>'id DESC',
        ),
        'pagination'=>array(
            'pageSize'=>15,
        ),
于 2012-09-06T07:18:51.033 回答