我有一个相当复杂的查询,我将 CSqlDataProvider 用于:
$sql = "
SELECT c.id AS id,
c.enabled AS enabled,
s.store_name AS store_name,
s.store_url AS store_url,
c.verified AS verified,
r.rating_total AS rating
FROM compete_settings c
LEFT JOIN stores s
ON c.compete_id = s.id
LEFT JOIN (
(SELECT store_id, rating_total FROM amazon_sellers)
UNION
(SELECT store_id, rating_total FROM ebay_sellers)
) AS r
ON c.compete_id = r.store_id
WHERE c.store_id = :store_id
";
$itemCount = Yii::app()->db->createCommand("SELECT COUNT(id) FROM compete_settings WHERE store_id = $store_id")->queryScalar();
return new CSqlDataProvider($sql, array(
'totalItemCount' => $itemCount,
'params' => array(
'store_id' => $store_id,
),
'sort' => array(
'attributes' => array ( 'enabled, store_name, rating' ),
'defaultOrder' => array('store_name'=>false)
),
'pagination' => array('pageSize' => Yii::app()->user->getState('pageSize_cs', Yii::app()->params['defaultPageSize']),),
));
查询效果很好。但是,这些列不可排序。
我确保使用 CSqlDataProvider 遵循Yii CGridview 排序,但它们仍然不是可点击的列标题。
这是我的列数组:
'columns' => array(
array(
'header' => 'Enabled',
'type'=>'raw',
'name'=>'enabled',
'htmlOptions'=>array('class'=>'enabled-column'),
'value' => 'CHtml::checkbox("", $data["enabled"], array("id"=>"c{$data[\'id\']}", "class"=>"enable-switch"))',
),
array(
'header' => 'Name',
'htmlOptions' => array('class' => 'account-name-column'),
'type' => 'raw',
'name'=>'store_name',
),
array(
'header' => 'Store Rating',
'name'=>'rating',
),
),
帮助?):