0

你好,谁能告诉我包含子网格值的本地数据的 json 格式。我使用了以下格式,但子网格数据没有加载到子网格表中。

var data=[{"Left_ssr_id":CaGM33098,"Mismatches":"6","Gaps":"1","AlignLen":"1119","Identity":"99.37","right_ssr_start":17308507,"Qstart":"33","query":"AB-Contig743","subject":"Ca7","Send":"17305359","Score":"2113","Evalue":"0.0","Left_ssr_end":17293825,"right_ssr_end":17308542,"right_ssr_id":CaGM33099 ,"Sstart":"17304241","Qend":"1150","Left_ssr_start":17293811,subgrid:[{"Right_ssr_start":17308507,"Right_ssr_end":17308542},{"Right_ssr_start":17308506,"Right_ssr_end":17308543}]}]

用于上传数据的代码。网格正在获取数据,但子网格仅显示标题和空白行。

$(document).ready(function(){
$("#blastform").submit(function(){
     jQuery.ajax({
         data: $(this).serialize(),
         url: this.action,
         type: this.method,
     dataType: "json",
         error: function() {
             $(thistarget).html("<span class='error'>Failed to submit form!</span>");
         },
         success: function(res) {
    var data=res;
$("#datatable").jqGrid({
    datatype:"local",
    data:data,
    colNames:['QueryID','SubjectID', . . . 'Right_nearest_distance'],
    colModel:[ {name:'query',index:'query', width:55},
        {name:'subject',index:'subject', width:80},
        .,
        .,
        {name:'right_near_dist',index:'right_near_dist', width:50, sortable:false}, ],
    rowNum:100,
    rowList:[100,200,500],
    pager: $('#pager2'),
    sortname: 'QueryID',
    viewrecords: true,
    sortorder: 'desc',
    loadonce: true,
    altRows: true,
    pgbuttons: true,
    subGrid : true,
    subGridUrl: 'local',
    subGridRowExpanded: function(subgrid_id, row_id)
    {
    var subgrid_table_id, pager_id;
    subgrid_table_id = subgrid_id+"_t";
    pager_id = "p_"+subgrid_table_id;
    $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
    jQuery("#"+subgrid_table_id).jqGrid({
    datatype: "local",
    colNames: ['ssr_start','ssr_end'],
    colModel: [ {name:"Right_ssr_start",index:"Right_ssr_start",width:80,key:true},
            {name:"Right_ssr_end",index:"Right_ssr_end",width:130},
             ], 
    rowNum:20,
    pager: pager_id,
    sortname: 'ssr_start',
    sortorder: "asc",
    height: '100%' });
    jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false}) },
    caption: 'Blast Results'
    });
    $("#datatable").jqGrid('navGrid','#pager2', {position: 'right'});
    jQuery("#datatable").jqGrid('navGrid','#blastresults',{edit:false,add:false,del:false});

         }
     })
     return false;
     }
);
);
4

2 回答 2

0

您需要配置 localReader 设置

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#array_data

于 2013-04-30T09:32:17.160 回答
0

我不建议您进行单独的 ajax 调用并使用datatype: "local", data: data. 你会有很多缺点。jqGrid 为datatype: "json"案例提供类型。可以使用其他选项,例如jsonReaderjsonmap来通知 jqGrid 如何从服务器响应中获取有关网格数据的信息。

您发布的值var data提供了错误的数据。您使用未定义的CaGM33098变量。CaGM33099如果您从服务器响应中使用 cut&pased,那么您会在服务器上生成错误的 JSON 响应。此外,subgrid如果data数组中的项目未包含在". 可能服务器从this.action(???this这里是什么???)以下数据返回

[
    {
        "Left_ssr_id": "CaGM33098",
        "Mismatches": "6",
        "Gaps": "1",
        "AlignLen": "1119",
        "Identity": "99.37",
        "right_ssr_start": 17308507,
        "Qstart": "33",
        "query": "AB-Contig743",
        "subject": "Ca7",
        "Send": "17305359",
        "Score": "2113",
        "Evalue": "0.0",
        "Left_ssr_end": 17293825,
        "right_ssr_end": 17308542,
        "right_ssr_id": "CaGM33099",
        "Sstart": "17304241",
        "Qend": "1150",
        "Left_ssr_start": 17293811,
        "subgrid": [
            {
                "Right_ssr_start": 17308507,
                "Right_ssr_end": 17308542
            },
            {
                "Right_ssr_start": 17308506,
                "Right_ssr_end": 17308543
            }
        ]
    }
]

旧答案答案显示了如何实现将嵌套数据显示为子网格。另一个答案显示了如何使用userdata直接从服务器加载嵌套数据。我建议您使用最后一种方法。

于 2013-05-01T10:53:33.003 回答