Dalam menampilkan data menggunakan widget cGridView Yii mungkin kita akan mendapatkan tampilan bahwa field yang terhubung ke tabel lain tidak tampil sortingnya. Beikut langkah-langkah penanganan supaya sorting tersebut bisa tampil
- Silahkan definisikan relasi dan sortingnya pada Controller misalnya
$detailDataProvider=new CActiveDataProvider(‘StoreItem’,array(
‘criteria’=>array(
‘condition’=>’store_id=:store_id’,
‘params’=>array(‘:store_id’=>$store_id_in),
‘with’=>array(
‘item’=>array(‘select’=>’item_code,item_name’),
‘item.basicUnit’=>array(‘select’=>’unit_code’),
),
),
‘sort’=>array(
‘attributes’=>array(
‘item_code’=>array(
‘asc’=>’item.item_code’,
‘desc’=>’item.item_code DESC’,
),
‘item_name’=>array(
‘asc’=>’item.item_name’,
‘desc’=>’item.item_name DESC’,
),
‘unit_code’=>array(
‘asc’=>’basicUnit.unit_code’,
‘desc’=>’basicUnit.unit_code DESC’,
),‘*’,
),
),‘pagination’=>array(
‘pageSize’=>10,
),
));$this->render(‘listinfo’,array(
‘detailDataProvider’=>$detailDataProvider,
)); - Tampilkan pada viewnya misalnya
$this->widget(‘zii.widgets.grid.CGridView’, array(
‘id’=>’store-item-grid’,
‘ajaxUpdate’=>false,
‘dataProvider’=>$detailDataProvider,
‘columns’=>array(
array(
‘class’=>’CButtonColumn’,
‘template’ => ‘{view}’,
‘buttons’ => array(
‘view’ => array(
‘label’=>’View’,
‘url’=>’Yii::app()->createUrl(“storeItemHistory/listinfo”, array(“item_id” => $data->item_id,”store_id” => $data->store_id))’,
),
),
),
array(‘name’=>’item_code’, ‘value’=>’$data->item->item_code’),
array(‘name’=>’item_name’, ‘value’=>’$data->item->item_name’),
‘qty_in’,
‘qty_out’,
‘qty_balance’,
array(‘name’=>’unit_code’, ‘value’=>’$data->item->basicUnit->unit_code’),
‘last_time_update’,
),
));
Kunjungi www.proweb.co.id untuk menambah wawasan anda.
ORM sort pada cGridView Yii