I'm new to JqGrid. I'm trying to make a grid with products. For each product I want a subgrid showing orders.
I can't load data in the subgrids. The 'load_sub_data_json.php' is never loaded…
Here's the JS my HTML file:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<div class="sfcode"><pre><br /> jQuery(document).ready(function() {<br /> $("#list").jqGrid({<br /> height: 'auto',<br /> blockui: true,<br /> altRows: true,<br /> loadonce: true,<br /> url:'load_main_data_json.php',<br /> datatype: 'json',<br /> mtype: 'GET',<br /> colNames:['ProductCode','ProductName', 'ProductVendor'],<br /> colModel :[<br /> {name:'productcode', index:'productcode', width:100, align:'right'},<br /> {name:'productname', index:'productname', width:280, align:'right'},<br /> {name:'productvendor', index:'productvendor', width:200, align:'right'}<br /> ],<br /> rowNum:35,<br /> rowList:[25,50,75,100,125,150,175,200],<br /> sortname: 'productcode',<br /> sortorder: 'desc',<br /> viewrecords: true,<br /> caption: 'My first grid',<br /> subGrid: true,<br /> subGridUrl: 'load_sub_data_json.php',<br /> subGridModel: [<br /> { name : ['Order number','Order date','Shipped date','Comments'],<br /> index : ['orderNumber', 'orderDate', 'shippedDate', 'comments'],<br /> width : [55,100,100,200],<br /> align : ['right','right','right','right'],<br /> params: ['productcode']<br /> }<br /> ]<br /> });<br /> });<br /> |
And this is my php-file loading data to the subgrid:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<div class="sfcode"><pre><br /> <br /> include("dbconfig.php");<br /> <br /> $id = $_REQUEST['id'];<br /> $productCode = $_REQUEST['productcode']; // param passed by query<br /> <br /><br /> // connect to the database<br /> $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());<br /> <br /> // select database<br /> mysql_select_db($database) or die("Error conecting to db.");<br /> <br /> // select columns<br /> $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. "';";<br /> <br /> $result = mysql_query( $SQL ) or die("CouldnÂ’t execute query.".mysql_error());<br /> <br /> $response = new stdClass;<br /> $i=0;<br /> while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {<br /> $response->rows[$i]['id']=$row['orderNumber'];<br /> $response->rows[$i] ['cell']=array($row['orderNumber'],$row['orderDate'],$row['shippedDate'],$row['comments']);<br /> $i++;<br /> }<br /> <br /> echo json_encode($response);<br /> <br /> |
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top