Hello all, first post here and new to yii.
I have a question about sorting in CGridView, but first, is there some kind of tutorial that walks
you through each class, giving concrete examples on their usage. I did the blog tutorial, and I
read the guide, but I still feel lost. I’m an experienced OOP PHP developer who completely understand
MVC programming and other applicable design patterns. Anyway, onto my real question.
Here’s my index action:
$criteria = new CDbCriteria(array(
'condition' => 'is_retired = 0',
'order' => 'last_name ASC'
));
$dataProvider = new CActiveDataProvider('User', array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 10
),
'sort' => array(
'attributes' => array(
'first_name',
'last_name',
'email',
'home_phone',
'cell_phone',
'last_login'
)
)
));
$this->render('index',array(
'dataProvider' => $dataProvider,
'model' => new User('search')
));
Gii had originally generated this:
$model=new User('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['User'])) $model->attributes=$_GET['User'];
$this->render('index',array(
'model'=>$model,
));
When I modified it, the sorting & filtering stopped working in the view. Here’s the code I’m using:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$dataProvider,
'filter'=>$model,
'columns'=>array(
'first_name',
'last_name',
'email',
'home_phone',
'cell_phone',
'is_allowed_access',
array(
'name' => 'last_login',
'value' => '$data->last_login ? date("m/d/Y h:ia", strtotime($data->last_login)) : ""'
),
'is_retired',
array(
'class'=>'CButtonColumn',
),
),
));
Thanks for any help!