0
我發現了一個類似的問題,但它並沒有幫助我(也沒有其他提問者顯然......)。所以在這裏:子網格數據未加載
我試圖使產品的網格。對於每個產品,我想要一個顯示訂單的子網格。
我無法在子網格中加載數據。在 'load_sub_data_json.php' 是永遠不會加載中...
這裏的JS我的HTML文件:
<pre>
jQuery(document).ready(function() {
$("#list").jqGrid({
height: 'auto',
blockui: true,
altRows: true,
loadonce: true,
url:'load_main_data_json.php',
datatype: 'json',
mtype: 'GET',
colNames:['ProductCode','ProductName', 'ProductVendor'],
colModel :[
{name:'productcode', index:'productcode', width:100, align:'right'},
{name:'productname', index:'productname', width:280, align:'right'},
{name:'productvendor', index:'productvendor', width:200, align:'right'}
],
rowNum:35,
rowList:[25,50,75,100,125,150,175,200],
sortname: 'productcode',
sortorder: 'desc',
viewrecords: true,
caption: 'My first grid',
subGrid: true,
subGridUrl: 'load_sub_data_json.php',
subGridModel: [
{ name : ['Order number','Order date','Shipped date','Comments'],
index : ['orderNumber', 'orderDate', 'shippedDate', 'comments'],
width : [55,100,100,200],
align : ['right','right','right','right'],
params: ['productcode']
}
]
});
});
</pre>
,這是我的PHP文件加載數據到亞格:
<pre>
include("dbconfig.php");
$id = $_REQUEST['id'];
$productCode = $_REQUEST['productcode']; // param passed by query
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());
// select database
mysql_select_db($database) or die("Error conecting to db.");
// select columns
$SQL = "select o.orderNumber, o.orderDate, o.shippedDate, o.comments from orderdetails d inner join orders o on o.orderNumber = d.orderNumber where d.productcode='" . $id. "';";
$result = mysql_query($SQL) or die("Couldnt execute query.".mysql_error());
$response = new stdClass;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$response->rows[$i]['id']=$row['orderNumber'];
$response->rows[$i] ['cell']=array($row['orderNumber'],$row['orderDate'],$row['shippedDate'],$row['comments']);
$i++;
}
echo json_encode($response);
</pre>
不行不行! – olefrank 2013-03-17 09:27:31