【问题标题】:Subgrid expand but dont show info子网格展开但不显示信息
【发布时间】:2013-01-21 11:56:28
【问题描述】:

我的网格有点奇怪,不知道为什么。我已经创建了几个子网格,并且在这个网格中从来没有遇到过问题,但是我的出生很困难。主网格的信息显示没有任何问题,但子网格不显示任何内容。

也就是说,他甚至成功的给子网格提供了php json。我试图享受另一个必须工作的子网格,我正在更改 url、字段等,只有当我更改主网格的 url 时,它才能让我显示。为什么有人知道?

jQuery("#organismos").jqGrid({
    url: 'model/ministerio/mod_organismo.php',
    colNames:['Cód. Organismo','Data Efetiva','Estado', 'Sigla', 'Designação curta', 'Designação longa', 'Última alteração', 'Alterado pelo utilizador'],
    colModel:[
        {name:'COD_ORG',index:'COD_ORG',width:80, align:'center', editable:true, editrules:{required:true}, editoptions:{size: 5 ,maxlength:4}, formoptions: { elmsuffix: ' *'}},
        {name:'DATA_EFETIVA',index:'DATA_EFETIVA',width:100,align:'center',datefmt: 'Y/M/d', editrules:{date:true},editable:true,editoptions:{ size: 11, maxlength: 10,dataInit: function(element) {$(element).datepicker({dateFormat: date_format, autosize:true})}}, formoptions: { elmsuffix: ' *'}},
        {name:'ESTADO_DTEF',index:'ESTADO_DTEF',width:50, align:'center',edittype:'select', editoptions:{value:{A:'Ativo',I:'Inativo'}}, editable:true, editrules:{required:true}, formoptions: { elmsuffix: ' *'}},
        {name:'SIGLA_ORG',index:'SIGLA_ORG',width:80, align:'center', editable:true, editrules:{required:true}, editoptions:{size: 13 ,maxlength:12}, formoptions: { elmsuffix: ' *'}},
        {name:'DESC_C_ORG',index:'DESC_C_ORG', width:150, align:'center', editable:true, editoptions:{size: 31, maxlength:30}},
        {name:'DESC_L_ORG',index:'DESC_L_ORG', width:300, align:'center', edittype:'textarea' ,editable:true, editrules:{required:true}, editoptions:{size: 31, maxlength:150}, formoptions: { elmsuffix: ' *'}},
        {name:'DATA_ULT_ALT',index:'DATA_ULT_ALT', hidden:true},
        {name:'UTILIZADOR',index:'UTILIZADOR', hidden:true}
    ],
    sortname: 'DATA_EFETIVA',
    caption:"Objetivo do Projeto",
    pager: '#pager1',
    height:'400',
    multiselect: false,
    subGrid: true,
    subGridOptions: { "plusicon" : "ui-icon-triangle-1-e",
                      "minusicon" :"ui-icon-triangle-1-s",
                      "openicon" : "ui-icon-arrowreturn-1-e",
                      "reloadOnExpand" : false,
                      "selectOnExpand" : true },
    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({
            url:"model/objetivos/mod_obj_estrategicos.php?idorg="+row_id,
            colNames:['Cód. Obj. Estratégico','Data Efetiva','Estado', 'Designação curta', 'Designação longa', 'Peso', 'Última alteração', 'Alterado pelo utilizador'],
            colModel:[
                {name:'COD_OBJ_EST',index:'COD_OBJ_EST', width:80, align:'center', editable:true, editrules:{required:true}, editoptions:{size: 5 ,maxlength:4}, formoptions: { elmsuffix: ' *'}},
                {name:'DATA_EFETIVA',index:'DATA_EFETIVA',width:100,align:'center',editable:true,editoptions:{ size: 11, maxlength: 10,dataInit: function(element) {$(element).datepicker({dateFormat: date_format, autosize:true})}}, formoptions: { elmsuffix: ' *'}},
                {name:'ESTADO_DTEF',index:'ESTADO_DTEF', width:50, align:'center',edittype:'select', editoptions:{value:{A:'Ativo',I:'Inativo'}}, editable:true, editrules:{required:true}, formoptions: { elmsuffix: ' *'}},
                {name:'DESC_C_OBJ_EST',index:'DESC_C_OBJ_EST', width:100, align:'center' ,editable:true, editrules:{required:true}, editoptions:{size: 31 ,maxlength:30}, formoptions: { elmsuffix: ' *'}},
                {name:'DESC_L_OBJ_EST',index:'DESC_L_OBJ_EST', width:300, align:'center', edittype:'textarea' ,editable:true, editrules:{required:true}, editoptions:{size: 31 ,maxlength:150}, formoptions: { elmsuffix: ' *'}},
                {name:'PESO',index:'PESO', width:50, align:'center',editable:true, editrules:{required:true, number: true}, editoptions:{size: 6 ,maxlength:5}, formoptions: { elmsuffix: ' *'}},
                {name:'DATA_ULT_ALT',index:'DATA_ULT_ALT', hidden:true},
                {name:'UTILIZADOR',index:'UTILIZADOR', hidden:true}
            ],
            rowNum:20,
            pager: pager_id,
            sortorder: "asc",
            editurl:"controller/objetivos/Estrategicos.php?idorg=" +row_id,
            height: '100%',
            autowidth: true
        });
        jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:true,add:true,del:true, view:true});
    }
});

网格 1 中的 JSON 结果:

{"page":"1","total":1,"records":"3","rows":[{"id":"1 ","cell":["1 ","2012\/10\/24","Ativo","Ta","funcionar?","OK","2012\/10\/18 13:49:35","1"]},{"id":"21 ","cell":["21 ","2012\/10\/31","Ativo","aa","aaa","oaa","2013\/01\/17 10:59:52","1"]},{"id":"12 ","cell":["12 ","2013\/01\/09","Ativo","TEJO","rio","rio","2013\/01\/03 18:21:40","1"]}]}

当我在网格 1 中选择一行时,从网格 2 生成 JSON:

{"page":"1","total":1,"records":"3","rows":[{"id":"AAASwaAAEAAAAC7AAA","cell":["12 ","2013\/01\/03","Ativo","1","1","1","2013\/01\/18 15:00:46","1"]},{"id":"AAASwaAAEAAAAC\/AAA","cell":["3 ","2012\/11\/01","Ativo","Barcelona","Juventus","14.9","2012\/12\/28 14:49:57","1"]},{"id":"AAASwaAAEAAAAC8AAB","cell":["4 ","2012\/12\/24","Ativo","Sim","ok","75.69","2012\/12\/28 14:50:33","1"]}]}

【问题讨论】:

  • 您应该提供创建 jqGrid 的 JavaScript 代码。此外,重要的是拥有用于填充主网格和不会消耗的子网格的测试 JSON 数据。典型的错误可能是 id 重复或其他一些不清楚的 id 工作。请参阅 the answer 作为此类问题的示例。
  • @Oleg 是的,但我认为不会。在此更改之前,我有两个网格来承载一行网格“实体”,并在有关此 ID 的所有其他网格信息中显示。现在是想改进它,而不是去访问。 (已经编辑了主帖)
  • 您没有发布任何 JSON 测试数据。主网格需要 JSON,子网格需要 JSON。您不要在 jqGrid 中使用 idPrefix。所以你可以很容易地收到 id 重复的问题。
  • 好的,现在在这里进行测试。但在此之前,id 很难复制,因为一个来自 id “body”,另一个来自 subgrid,rowid 是来自数据库 oracle 的 id
  • 对不起,我想你还是不明白这个问题。如果您只是使用数据库中的 id 并将例如 多次相同的 id 用于不同的子网格,您可以很容易地收到 id 重复的问题。可能你的情况还有另一个问题,但要解决这个问题,首先应该能够重现它。您可以使用 Fiddler、Firebug 或 IE 或 Chrome 的开发人员工具来捕获来自服务器的 HTTP 响应,其中包含 JSON 数据,可用于在没有后端的情况下重现问题。

标签: php oracle jqgrid


【解决方案1】:

就像我之前在 cmets 中写的那样,问题的原因是 id 的值错误。如果从 id 中删除尾随空格("1 ""1""21 ""21""12 ""12")原始的 non-working grid 将是 working

【讨论】:

  • 我只是发现了一点,也改变了整个数据库。无论如何,再次非常感谢你。
  • 我会再问一个问题,不必打开另一个话题。如何知道何时扩展子网格具有定义的高度,有时对主网格来说太清楚了。有没有办法根据网格的可用空间来设置大小?
  • @UZUMAKI:抱歉,我不确定我是否理解正确。通常我在网格中使用height: "auto"height: "100%"。所以网格的高度会自动扩展,没有不需要的滚动条。此外,我使用 always gridview: true 来提高性能并使用autoencode: true 来确保任何数据都可以正确显示在网格中。见the modified demo
  • 你理解的很好。顺便说一句,我没有想到它是愚蠢的。谢谢你。虽然德国会给你一顿午餐。再次感谢
【解决方案2】:

我不确定我在这里缺少什么,但我无法在子网格中找到数据,尽管我在父网格中看到数据并能够扩展它....

  var myData =   
  {"page":"1","total":"1","records":"2","rows":[{"id":"591","cell":["07/10/2013","Vas Editor","Workflow Transfer","All","1","591","null","2013-07-10 11:00:22",{"cell":["07/10/2013","Vas Editor","Workflow Transfer","All","1","591","null","2013-07-10 11:00:22",null]}]},{"id":"592","cell":["07/10/2013","Vas Editor","Pending Requirements","All","2","592","null","2013-07-10 11:00:35",{"cell":["07/10/2013","Vas Editor","Pending Requirements","All","2","592","null","2013-07-10 11:00:35",null]}]}],"message":""
  };


    jQuery("#noteTable").jqGrid({
    datatype : "local",     
    colNames : [ 'Date', 'User Name', 'Tag(s)', 'Applicant', 'Note', 'Id','Applicant Id','Date TS','subRow'],
    colModel : [ 
        {name : 'date', index : 'date', width : 120 }, 
        {name : 'userName', index : 'userName', width : 150 }, 
        {name : 'tags', index : 'tags', width : 150 }, 
        {name : 'applicant', index : 'applicant', width : 150, editable : true }, 
        {name : 'note', index : 'note', width : 150 }, 
        {name : 'id', index : 'id', hidden : true } , 
        {name : 'applicantId', index : 'applicantId', hidden : true},
        {name : 'dateTS', index : 'dateTS', hidden : true},
        {name : 'subRow', index : 'subRow', hidden : true}

    ],
    rowNum : 10,
    rowList : [ 10, 20, 30 ],
    pager : '#notesTablePager', // un comment this line to see the pagination bar
    sortname : 'dateTS',
    viewrecords : true,
    sortorder : "desc",
        idPrefix: "m",
subGrid: true,
subGridRowExpanded: function(subgrid_id, row_id) {
var data = $("#noteTable").jqGrid("getLocalRow", row_id);
// we pass two parameters
// subgrid_id is a id of the div tag created within a table
// the row_id is the id of the row
// If we want to pass additional parameters to the url we can use
// the method getRowData(row_id) - which returns associative array in type name-value
// here we can easy construct the following
console.log('row_id****'+row_id);
console.log('searchData *****'+searchData);
    console.log('myData *****'+myData);
    var localRowData1 = $(this).jqGrid('getLocalRow', row_id);
    var localRowData = $("#noteTable").jqGrid('getLocalRow', row_id).cell;
    console.log('localRowData1 ***************'+localRowData1);
    console.log('localRowData ***************'+localRowData);

   var subgrid_table_id;
   var subgridTableId = subgrid_id + "_t"; 
   $("#" + subgrid_id).html("<table id='" + subgridTableId + "'></table>");       
   $("#" + subgridTableId).jqGrid({      
        datatype: "local",            
        data: data.cell,
        colNames : [ 'Date', 'User Name', 'Tag(s)', 'Applicant', 'Note', 'Id','Applicant Id','Date TS' ],
        colModel : [ 
                    {name : 'date', index : 'date', width : 120 }, 
                    {name : 'userName', index : 'userName', width : 150 }, 
                    {name : 'tags', index : 'tags', width : 150 }, 
                    {name : 'applicant', index : 'applicant', width : 150, editable : true }, 
                    {name : 'note', index : 'note', width : 150 }, 
                    {name : 'id', index : 'id', hidden : true } , 
                    {name : 'applicantId', index : 'applicantId', hidden : true},
                    {name : 'dateTS', index : 'dateTS', hidden : true}
    ],
      height: '100%',
      rowNum:20,
      sortname: 'Date',
      sortorder: "desc",
      idPrefix: "s_" + row_id + "_"
   })

}

}).navGrid('#notesTablePager', {add : false, edit : false, del : false});
$("#noteTable").setGridParam({datatype : 'json',loadonce : true});
$("#noteTable")[0].addJSONData(myData); 
$("#noteTable").setGridParam({datatype : 'local'});
$("#noteTable").setGridParam({pagination : true});
$("#notesResultDiv").css("display", "inline");
$("#noteTable").trigger('reloadGrid');

【讨论】:

  • 欢迎来到 SO。您的回答似乎有点令人困惑,因为您回答了这个问题,但随后又自相矛盾地说“我不确定我在这里遗漏了什么,但我无法在子网格中找到数据,尽管我在父网格中看到数据并且能够扩展它。 ……”。以后,请确保您在发布之前已经对您的答案进行了全面审查(测试过)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-09
  • 2014-10-17
  • 2021-05-22
相关资源
最近更新 更多