I have a 2 problems in my code: 1) You cannot do a sort by header "Title" when you click on it. 2) You can click on the title, think that will sort alphabetically, an arrow appears, but nothing happens, no sorting.
site/index.php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'title' => array(
'class'=>'CLinkColumn',
'labelExpression' => '$data->title',
'urlExpression'=>'Yii::app()->request->baseUrl."/page/".$data->id',
'header'=>'Title',
'headerHtmlOptions' => array('style'=>'width:250px;'),
),
'created' => array(
'name' => 'created',
'value' => 'date("j.m.Y H:i", $data->created)',
'headerHtmlOptions' => array('style'=>'width:90px;'),
),
'category_id' => array(
'name' => 'category_id',
'value' => '$data->category->title',
'filter' => Category::allCategory(),
'headerHtmlOptions' => array('style'=>'width:150px; text-align:center;'),
),
'subcategory_id' => array(
'name' => 'subcategory_id',
'value' => '$data->subcategory->title',
'filter' => Subcategory::allCategory(),
'headerHtmlOptions' => array('style'=>'width:150px; text-align: center;'),
),
'condition_id' => array(
'name' => 'condition_id',
'value'=> '$data->condition->title',
'filter' => Condition::allAttributes(),
'headerHtmlOptions' => array('style'=>'width:90px;'),
),
),
));
SiteController
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Page', array(
'criteria'=>array(
'order'=>'id DESC',
),
'pagination'=>array(
'pageSize'=>30,
),
));
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index', array('dataProvider'=>$dataProvider));
}
This controller has not model.