我正在尝试将php脚本的输出加载到jqgrid中,但我可以看到没有数据的表。
<div id='Results'>
<div id= 'abcd' style="display:block";>
<?php include("simple.php");?>
</div>
<script type="text/javascript">
jQuery(function($) {
var data= $('#abcd').text();
var data1= data.replace(/\"/ig,'\"');
var data1= data1.replace(/[\“\”\″]/ig,'\"');
jQuery("#tableid").jqGrid({
dataType: "json",
data:data1,
colNames:['snp_id','chr','start_pos','end_pos','class','refbase','variantbase'],
colModel:[
{name:'snp_id',index:'snp_id', width:50},
{name:'chr',index:'chr', width:50},
{name:'start_pos',index:'start_pos', width:60},
{name:'end_pos',index:'end_pos', width:75},
{name:'class',index:'class', width:75, align:"right" },
{name:'refbase',index:'refbase', width:75},
{name:'variantbase',index:'variantbase', width:150}
],
pager: '#pager',
rowNum:100,
sortname: 'snp_id',
sortorder: "asc",
viewrecords: true,
gridview: true,
height: '100%',
width: '100%',
caption:"Title",
loadComplete: function(reload) {
jQuery("#myGridID").trigger("reloadGrid");
}
});
});
</script>
Simple.php以JSON格式检索名为'abcd'
的div的数据{"total":1,"page":1,"records":5,"rows":[{"id":"CaSNP000002","cell":[{"snp_id":"CaSNP000002","chr":"Ca4","start_pos":"10077235","end_pos":"10077254","class":"D","refbase":"CTCTCTCTCTCTCTCTCTCT","variantbase":null}]},{"id":"CaSNP000003","cell":[{"snp_id":"CaSNP000003","chr":"Ca4","start_pos":"10077245","end_pos":"10077254","class":"D","refbase":"CTCTCTCTCT","variantbase":null}]},{"id":"CaSNP000004","cell":[{"snp_id":"CaSNP000004","chr":"Ca4","start_pos":"10077253","end_pos":"10077254","class":"D","refbase":"CT","variantbase":null}]},{"id":"CaSNP000005","cell":[{"snp_id":"CaSNP000005","chr":"Ca4","start_pos":"10077254","end_pos":"10077255","class":"I","refbase":"------ ","variantbase":"CTCTCT"}]},{"id":"CaSNP000006","cell":[{"snp_id":"CaSNP000006","chr":"Ca4","start_pos":"10077254","end_pos":"10077255","class":"I","refbase":"-------- ","variantbase":"CTCTCTCT"}]}]}
答案 0 :(得分:0)
尝试使用此代码...我不是100%它会工作:)
P.S&GT;更新..如果它不工作尝试调试你的问题..搜索错误使用控制台日志等..没有错误它不容易找到你的问题
<div id= 'abcd' style="display:block";>
<?php include("simple.php");?>
</div>
<script type="text/javascript">
jQuery(function($) {
var data= $('#abcd').text();
data = jQuery.trim(data); // to remove all empty spaces else json parse may fail
data = jQuery.parseJson(data); // parsing string to json object/array
jQuery("#tableid").jqGrid({
datatype: "local",
colNames:['snp_id','chr','start_pos','end_pos','class','refbase','variantbase'],
colModel:[
{name:'snp_id',index:'snp_id', width:50},
{name:'chr',index:'chr', width:50},
{name:'start_pos',index:'start_pos', width:60},
{name:'end_pos',index:'end_pos', width:75},
{name:'class',index:'class', width:75, align:"right" },
{name:'refbase',index:'refbase', width:75},
{name:'variantbase',index:'variantbase', width:150}
],
pager: '#pager',
rowNum: data.rows.length,
sortname: 'snp_id',
sortorder: "asc",
viewrecords: true,
gridview: true,
height: '100%',
width: '100%',
caption:"Title",
loadComplete: function(reload) {
jQuery("#myGridID").trigger("reloadGrid");
}
});
var mydata = data.rows;
for(var i=0;i<=mydata.length;i++)
jQuery("#tableid").jqGrid('addRowData',i+1,mydata[i]);
});
</script>
答案 1 :(得分:0)
我根据你的代码片段进行了一些演示,使用如下数据类型:
datatype: 'jsonstring',
datastr:data,
终于为我填充了网格。我从这里找到了解决方案https://stackoverflow.com/a/6833082/1945020