Halo Yii-ers …
Thread pertamax nih
oia saya mau tanya soal grid-grid
awalnya ane liat-liat disini… http : //wwwjeasyuicom/tutorial/datagrid/datagrid22_demo.html
source code / dokumentasi dari sononya kurang lebih seperti ini : http : //wwwjeasyuicom/tutorial/datagrid/datagrid22.php
trus ane rubah-rubah dikit disesuaikan dengan aplikasi di ane. Masih menggunakan PHP dan Query (tanpa Yii)
dan bisa jalan…
kemudian ane coba masukkan ke Yii…
ane bikin fungsi di controller dengan nama getData ama getDetail…
controller >>
public function actionGetdata(){
$result = array();
$rs = Users::model()->findAll();
$items = array();
foreach($rs as $row)
{
array_push($items, $row->getAttributes(array('id','username', 'fname', 'lname')));
}
echo json_encode($items);
}
public function actionGetdetail(){
$itemid = $_GET['owner'];
$rs = Units::model()->findAllByAttributes(array('owner'=>$itemid));
$items = array();
foreach($rs as $row)
{
$items[] = $row->getAttributes(array('name', 'imei', 'tipe', 'no_sim_card', 'status_gprs', 'gmt'));
}
echo json_encode($items);
}
oia ane juga udah set access Rule nya untuk getData dan getDetail.
dan untuk view nya kurang lebih seperti ini
View >>
<?php
$url = Yii::app()->baseUrl;
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile(bu().'/js/jquery-easyui-1.2.6/jquery-1.7.2.min.js');
$cs->registerScriptFile($url.'/js/data-grid/jquery.easyui.min.js');
$cs->registerScriptFile($url.'/js/data-grid/datagrid-detailview.js');
?>
<link rel="stylesheet" type="text/css" href="<?php echo $url.'/css/demo.css'?>">
<link rel="stylesheet" type="text/css" href="<?php echo $url.'/css/easyui.css'?>">
<link rel="stylesheet" type="text/css" href="<?php echo $url.'/css/icon.css'?>">
<?php
Yii::app()->clientScript->registerScript("detailView", "
$(function(){
$('#dg').datagrid({
view: detailview,
detailFormatter:function(index,row){
return '<div style=\"padding:2px;background-color:#6495ed;\"><table id=\"ddv-'+index+'\"></table></div>';
},
onExpandRow: function(index,row){
$('#ddv-'+index).datagrid({
url:'getdetail?owner='+row.id,
fitColumns:true,
singleSelect:true,
height:'auto',
columns:[[
{field:'name',title:'Nama Unit',width:100},
{field:'imei',title:'No. IMEI',width:100},
{field:'tipe',title:'Tipe GPS',width:100},
{field:'no_sim_card',title:'Nomor SIM Card',width:100},
{field:'status_gprs',title:'Status GPRS',width:100},
{field:'gmt',title:'GMT',width:100}
]],
onResize:function(){
$('#dg').datagrid('fixDetailRowHeight',index);
},
onLoadSuccess:function(){
setTimeout(function(){
$('#dg').datagrid('fixDetailRowHeight',index);
},0);
}
});
$('#dg').datagrid('fixDetailRowHeight',index);
}
});
});
", CClientScript::POS_HEAD);
?>
<table id="dg" style="height:350px; weight: 750px"
url="<?php echo CController::createUrl('users/getdata')?>"
title="Unit List "
singleSelect="true" fitColumns="true">
<thead>
<tr>
<th field="username" width="80">Username</th>
<th field="fname" width="100">Nama Depan</th>
<th field="lname" align="right" width="80">Nama Belakang</th>
</tr>
</thead>
</table>
yang jadi pertanyaan ane …
kira-kira kenapa ya sob, data tidak muncul / terload di grid.
Mohon masukannya…
thnks before