I'm trying to display the database in jqxgrid on page load using jquery, but the screen shows nothing.
I have a few pages to apply this technique to, and one of the page I've managed to do it using javascript. Then the second page is done using jquery. But on the third page (also using jquery), I get nothing.
this is the jquery in view_page.php:
<html>.... //view_page./
$(document).ready(function () {
var param = '<?php echo $formdata->doc_num;?>';
var array_grid_key = <?php echo json_encode($v_arrayGridKey2);?>;
$.ajax({
url:"<?php echo base_url('index.php/px/pxq/sel_head');?>/"+param,
dataType: "json",
success:function(result){
var dataFields = new Array();
$("#ajax").html(result);
for(var i = 0;i<array_grid_key.length;i++){
var obj = {name: array_grid_key[i]};
dataFields.push(obj);
}
var source = {
datafields: dataFields,
localdata: result
};
var dataAdapter = new $.jqx.dataAdapter(source);
dataAdapter.dataBind();
var dataSource = {
datafields: dataFields,
localdata: result
};
var adapter = new $.jqx.dataAdapter(dataSource);
$("#data_grid").jqxGrid({ source: adapter });
}
});
});
....</html>
this is the controller:
public function sel_head($code){
$this->load->model('px');
$this->data['ajax'] = $this->px->querying(
'select t3.code as \'code\', t3.name as \'name\', t2.item_d1 as \'item_d1\', t2.item_d2 as \'item_d2\',t2.item_qty as \'item_qty\', t2.item_price as \'item_price\', t2.item_disc_pct1 as \'item_disc_pct1\', t2.item_disc_pct2 as \'item_disc_pct2\', t2.item_netprice as \'item_netprice\', t2.item_total as \'item_total\'
from spurc_h t1
inner join spurc_d t2 on t1.doc_id = t2.doc_id
inner join sttem_m t3 on t2.id = t3.id
inner join sbuss t4 on t4.buss_code = t1.buss_code
where doc_num = \''.$code.'\''
);
echo json_encode($this->data['ajax']);
}
The most confusing part is why it works on 2nd page, but not on 3rd page.
Chrome developer tool shows it returns the query result as expected (json format), but we can't put it to the jqxgrid using the jquery above..
I want to use it as a tools, because so many pages need to be done like this. using the same technique will save the development time.
Please tell me what i miss here.. Appreciate your help :)