我正在使用 CSqlDataProvider 构造 CGridview 我不能使用 CActiveRecord,因为结果集很大并且会引发内存错误。列需要是可排序的。我应该如何实现这一目标?
示例 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 = new CSqlDataProvider($orders_query_raw, array(
'totalItemCount'=>$count, // get from a count query
'pagination'=>array(
'pageSize'=>50,
),
));
和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\']))',
),
),
),
),
));
谢谢