I'm having trouble using the jQgrid, when I initialize the jqgrid with json datatype it results to an error:
obj is undefined
ret = obj[expr];
When I initialize the jqgrid with local datatype, the error will not occur but the json data will not be loaded
index.html
<table id="products"></table>
<div id="pager"></div>
<script type="text/javascript">
$('document').ready(function(){
jQuery("#products").jqGrid({
url: 'product.php',
editurl: 'product_update.php',
datatype: "json",
mtype: 'POST',
colNames:['Product Name'],
colModel:[
{name:'product_name',index:'product_name', width:90}
],
rowNum:-1,
viewrecords: true,
rowList:[10,20,30],
pager: '#pager',
toolbar : [true,"top"],
sortorder: "DESC",
caption:"Products",
width: 940,
height: "100%"
});
});
</script>
product.php (this is a mock data only)
$arrayName = array();
$arrayName['page'] = 1;
$arrayName['total'] = 1;
$arrayName['records'] = 3;
$arrayName['rows'][0] = array(
'product_name' => 'Product X'
);
$arrayName['rows'][1] = array(
'product_name' => 'Product Y'
);
$arrayName['rows'][2] = array(
'product_name' => 'Product Z'
);
echo json_encode($arrayName);
json output:
{"page":1,"total":1,"records":3,"rows":[{"product_name":"Product X"},{"product_name":"Product Y"},{"product_name":"Product Z"}]}
I'm hoping someone can help me here.
Thank you in advance :D