未加载子网格数据 [英] Subgrid data not loaded
本文介绍了未加载子网格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了一个类似的问题,但这并没有帮助我(显然也没有其他提问者...).所以去了:
I found a similar question but it didn't help me (nor the other questioner apparently...). So here goes:
我正在尝试将产品与网格联系起来.对于每种产品,我想要一个显示订单的子网格.
I'm trying to make a grid with products. For each product I want a subgrid showing orders.
我无法在子网格中加载数据.永远不会加载'load_sub_data_json.php'...
I can't load data in the subgrids. The 'load_sub_data_json.php' is never loaded...
这是JS我的HTML文件:
Here's the JS my HTML file:
<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文件,将数据加载到子网格:
And this is my php-file loading data to the subgrid:
<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>
推荐答案
我认为您缺少subGridModel中的映射
I think you are missing the mapping in the subGridModel
尝试一下,添加
mapping : ['orderNumber', 'orderDate', 'shippedDate', 'comments'],
这篇关于未加载子网格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文