我发现了一个类似的问题,但它没有帮助我(显然也没有其他提问者......)。所以这里:
我正在尝试用产品制作网格。对于每个产品,我想要一个显示订单的子网格。
我无法在子网格中加载数据。永远不会加载'load_sub_data_json.php'......
这是我的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>
答案 0 :(得分:0)
我认为你缺少subGridModel中的映射
试试这个,添加
mapping : ['orderNumber', 'orderDate', 'shippedDate', 'comments'],