anu1992
(Avpin1992)
April 17, 2013, 10:08am
1
Hi, I am trying to implement sorting with Yii list view. I have joined 2 tables named provider_favourite and service_request in list view. And the fields and contents from both tables are listing in the list view. But sorting is working only in provider_favourite table, not from service_request table.How can I sort the fields from service_request table? Iam using csort for sorting. I also tried CGrid view. But the same problem is happening in grid view also …
Iam using the following code to join
$criteria = new CDbCriteria;
$criteria->select = 'favourite_notes,favourite, favourite_added_date,max_budget,preferred_location';
$criteria->join = 'LEFT JOIN service_request AS s ON service_request_id = favourite';
$criteria->condition = 'favourite_type = 1';
$sort=new CSort('ProviderFavourite');
$sort->defaultOrder='favourite_notes ASC,favourite_added_date asc,max_budget asc';
$sort->applyOrder($criteria);
$type = 2;
$data = new CActiveDataProvider('ProviderFavourite', array('criteria' => $criteria, 'pagination' => array('pageSize' => 4)
));
$this->renderPartial('favourites', array(
'ModelInstance' => ProviderFavourite::model()->findAll($criteria),
'dataProvider' => $data, 'type' => $type, 'sort'=>$sort,
));
If more details needed, I will provide. Thanks in advance
lalzada
(Lalzadamohmand)
April 17, 2013, 10:18am
2
try this
$sort->attributes = array(
'field_name1' => 'relation_name.field_name1',
'field_name2'
);
where field_name1 is from other table
and field_name2 is from same table
pass $sort like this in dataProvider
$data = new CActiveDataProvider('ProviderFavourite', array(
'criteria' => $criteria,
'pagination' => array('pageSize' => 4),
'sort'=>$sort
));
anu1992
(Avpin1992)
April 17, 2013, 10:58am
3
[size=2]Thanks, now a sort link is showing in the view, on clicking the page is also getting reloaded, but sorting is not done. I am using the following code to echo it[/size]
<?php echo $sort->link('max_budget'); ?>
is there any more changes required
lalzada
(Lalzadamohmand)
April 17, 2013, 11:07am
4
u passed sort attributes to ListView like this
$this->widget('LlistView', array(
'dataProvider' => $model,
'sortableAttributes' => array(
'field_name1',
'field_name2',
),
));
anu1992
(Avpin1992)
April 17, 2013, 11:21am
5
u passed sort attributes to ListView like this
$this->widget('LlistView', array(
'dataProvider' => $model,
'sortableAttributes' => array(
'field_name1',
'field_name2',
),
));
Yes, I had provided so…
$this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider,'itemView'=>'index_1',
'id'=>'request',
'template' => ' {items}{pager}',
'sortableAttributes'=>array('favourite_notes','max_budget','service_name')
));
but the same problem is showing
lalzada
(Lalzadamohmand)
April 17, 2013, 11:37am
6
edit $sort like this
$sort->attributes = array(
'field_name'=>array(
'asc'=>'relation_name.field_name ASC' ,
'desc'=>'relation_name.field_name DESC',
'label'=>'Display'
),
);
lalzada
(Lalzadamohmand)
April 17, 2013, 11:39am
7
anu1992
(Avpin1992)
April 17, 2013, 11:48am
8
edit $sort like this
$sort->attributes = array(
'field_name'=>array(
'asc'=>'relation_name.field_name ASC' ,
'desc'=>'relation_name.field_name DESC',
'label'=>'Display'
),
);
Thanks, it is not working, let me check the link you provided