So,I have my CGridviews, a couple of them, all working and displaying nicely.
The problem is, now i want to enable a user to sort by a certain property, by clicking on the column name.
I have tried to read around, but nothing seems to come close to what i want to achieve.
Here is the code for generating the data provider i use for one of the gridviews
<?php
$command = Yii::app()->db->createCommand();
$staff1 = $command->select('project.id,project.name, project.start_date, project.end_date, project.project_ref AS project_ref , technical.surname AS Technical, sales.surname AS ARM, sm.surname AS Manager,project.duration,project.status')
->from('project')
->leftjoin('staff technical','project.staff1=technical.id')
->leftjoin('staff sales','project.staff2=sales.id')
->leftjoin('staff sm','project.project_manager=sm.id')
->order('name')
->queryAll();
$provide= new CArrayDataProvider($staff1, array(
)); ?>
You can see i order them by default, according to the "name" property.
Then I display the data from the query with a gridview
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$provide,
'columns'=>array(
'project_ref'=>array('name'=>'Project Ref', 'value'=>'$data["project_ref"]'),
'name'=>array(
'name'=>'Project Name',
'type'=>'raw',
'value'=>'CHtml::link($data["name"], array("project/view", "id"=>$data["id"]))',),
'Technical'=>array('name'=>'ARM', 'value'=>'$data["Technical"]'),
'ARM'=>array('name'=>'Technical', 'value'=>'$data["ARM"]'),
'Manager'=>array('name'=>'Manager', 'value'=>'$data["Manager"]'),
'start_date'=>array('name'=>'Started', 'value'=>'$data["start_date"]','htmlOptions'=>array('style' => 'text-align: right;')),
'duration'=>array('name'=>'Duration(Weeks)', 'value'=>'$data["duration"]'),
'status'=>array('name'=>'%age ', 'value'=>'$data["status"]'),
),
)); ?>
Now i want, when a user clicks on the column name, the items in the grid view, are sorted by that column.
Thank