I'm using CSqlDataProvider to construct CGridview I cannot use CActiveRecord because the result set is huge and throwing memory errors. The columns need to be sortable. How should I achieve this?
Sample sql
$orders_query_raw = 'select o.order_id, o.customer_name, o.customer_email, o.customer_advertiser, o.payment_method, o.created, o.last_updated, o.currency, o.currency_value, o.status, o.blinking, s.name, ot.text order_total, o.customer_id, op.product_id, o.phonebooking
from `order` o, `order_total` ot, `order_status` s , order_product op
where o.order_id = op.order_id and o.status = s.order_status_id and ot.order_id = o.order_id and s.language_id = '1' and ot.class = 'ot_total' group by o.order_id'
sql dataprovider
$dataProvider = new CSqlDataProvider($orders_query_raw, array(
'totalItemCount'=>$count, // get from a count query
'pagination'=>array(
'pageSize'=>50,
),
));
And gridview
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'id'=>'order-grid',
'columns' => array(
array(
'header'=>'Order ID',
'value'=>array($this, 'gridOrderId'),
'type'=>'raw',
),
array(
'header'=>Yii::t('order', 'Customers'),
'name'=>'customer.fullName',
'value'=>'CHtml::link($data[\'customer_name\'], \'mailto:\'.$data[\'customer_email\'])',
'type'=>'raw',
),
array(
'header'=>Yii::t('order', 'Order total'),
'value'=>'strip_tags($data[\'order_total\'])',
'type'=>'raw',
'htmlOptions'=>array(
'style'=>'text-align:right;',
),
),
array(
'header' => Yii::t('order', 'Date Purchased'),
'name' => 'created',
),
array(
'header'=> Yii::t('order', 'Last modify date'),
'value'=>array($this, 'gridLastModified'),
),
array(
'header' => Yii::t('order', 'Status changed by'),
'value' => array($this, 'gridLastModifiedUserFirstName'),
),
array(
'header' => Yii::t('provider', 'Provider\'s code'),
'value' => array($this, 'gridProviderCode'),
'type' => 'raw',
'htmlOptions'=>array(
'class'=>'nobr',
),
),
array(
'header' => Yii::t('order', 'Follow up'),
'value' => array($this, 'gridFollowUp'),
'type' => 'raw',
),
array(
'header' => Yii::t('order', 'Order status'),
'value' => '$data[\'name\']',
),
array(
'class'=>'CButtonColumn',
'template'=>'{update}',
'header'=>'Action',
'buttons'=>array(
'update'=>array(
'url'=>'Yii::app()->createUrl(\'order/update\', array(\'order_id\'=>$data[\'order_id\']))',
),
),
),
),
));
Thanks