【问题标题】:Multiple DOJO Data-grids not displaying in Accordian Containers多个 DOJO 数据网格未显示在手风琴容器中
【发布时间】:2011-10-13 18:20:48
【问题描述】:

我有一个包含 3 个标签的页面 (dijit.layout.TabContainer),每个标签有 2-3 个手风琴 (dijit.layout.AccordionContainer)。在单个数据存储中,我尝试在每个手风琴中显示不同的网格。

我可以在一个手风琴中显示数据,但其他网格显示为空白,我什至看不到标题。如果我尝试在标签/手风琴之外显示多个网格,它工作正常。不知道我在这里缺少什么。

        var jsonStore = new dojo.data.ItemFileWriteStore({ data:{
   "identifier": "rowIdentifier",
   "label": "gridIdentifier",
   "items": [
      {
        "rowIdentifier": 123,
        "gridIdentifier": "labor",
         "description": "Project Manager",
         "hours": 100.0,
         "rate": 100.0
      },
      {
      "rowIdentifier": 234,
       "gridIdentifier": "oem",
         "description": "Developer",             
         "hours": 100.0,
         "rate": 100.0
      }
   ]
} });               
            var grid1 = null;   
            var grid2 = null;
            var grid1Layout= [
                { field: "rowIdentifier", width: "auto", name: "Row Identifier",hidden:true },
                { field: "gridIdentifier", width: "auto", name: "Grid Identifier",hidden:true },
                { field: "description", width: "auto", name: "Tier/Description", editable:true },

                { field: "hours", width: "auto", name: "Hours" },
                { field: "rate", width: "auto", name: "Rate <br/>" }               
            ];

            grid1 = new dojox.grid.DataGrid({
                query: { gridIdentifier: 'labor' },
                store: jsonStore,
                singleClickEdit: true,
                structure: grid1Layout,
                rowsPerPage: 6
            }, 'grid1Node');  

            var grid2Layout= [
                { field: "rowIdentifier", width: "auto", name: "Row Identifier",hidden:true },
                { field: "gridIdentifier", width: "auto", name: "Grid Identifier",hidden:true },
                { field: "description", width: "auto", name: "Tier/Description", editable:true },
                { field: "hours", width: "auto", name: "Hours" },
                { field: "rate", width: "auto", name: "Rate <br/>" }

            ];

            grid2 = new dojox.grid.DataGrid({
                query: { gridIdentifier: 'oem' },
                store: jsonStore,
                singleClickEdit: true,
                structure: grid2Layout,
                rowsPerPage: 6
            }, 'grid2Node');


         // Call startup, in order to render the grid:
            grid1.startup();
            grid2.startup(); 

下面是我的 HTML

<div style="height: 105px;">
                            <div dojoType="dijit.layout.TabContainer" style="width: 100%;"
                                doLayout="false">
                                <div dojoType="dijit.layout.ContentPane" title="Labor" selected="true">
                                    <div id="LaborAccordian" style="width:auto; height: 300px">
                                        <div dojoType="dijit.layout.AccordionContainer" style="height: 300px;">
                                            <div dojoType="dijit.layout.ContentPane" title="Tab1 Acc1" selected="true">
                                            <div id="grid1Node"></div></div>
                                            <div dojoType="dijit.layout.ContentPane" title="Tab1 Acc2"><div id="SubContractorLaborGridNode"></div></div>
                                            <div dojoType="dijit.layout.ContentPane" title="Tab1 Acc3"><div id="VendedLaborGridNode"></div></div>
                                        </div>
                                    </div>
                                </div>
                                <div dojoType="dijit.layout.ContentPane" title="OEM products">
                                    <div id="OEMAccordian" style="width:auto; height: 300px">
                                        <div dojoType="dijit.layout.AccordionContainer" style="height: 300px;">
                                            <div dojoType="dijit.layout.ContentPane" title="Tab2 Acc1"><div id="grid2Node"></div></div>
                                            <div dojoType="dijit.layout.ContentPane" title="Tab2 Acc2" selected="true"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- end of the div -->
                        </div>

我在 .请让我知道在不同的手风琴容器中以不同的风格显示相同的数据存储时缺少什么?

谢谢 SK

【问题讨论】:

    标签: datagrid dojo tabs


    【解决方案1】:

    根据您的描述,很可能网格已成功创建,但由于尺寸为 0 * 0 而未显示。这可能是因为在隐藏的手风琴窗格中创建网格时,网格的大小包含DOM 节点实际上为零。因此,当隐藏的手风琴窗格可见时,网格大小仍然为零。这也可能是由于在网格的包含节点中使用 CSS 指定了动态高度和宽度,例如使用高度或宽度,如100%。在计算实际高度和宽度时,动态高度或宽度可能会导致问题。

    所以我的建议是首先使用 Firebug 检查 DOM 结构,看看是否创建了网格。您很可能会看到网格的 DOM 结构,但它没有显示出来,因为大小为 0 * 0。您可以使用 Firebug 来验证它。如果是这种情况,您可以使用resize 函数手动指示网格再次重新计算其大小。您可以使用dojo.connect 连接到dijit.layout.AccordionPaneonSelected 函数并调用网格的resize 函数。然后当一个手风琴页面被选中时,它里面的网格会自动调整大小。

    【讨论】:

    • 我尝试了你的方法,这个想法似乎是正确的,但使用 dojo.connect 却不起作用。相反,我使用了旧帖子中给出的另一种方法。 dojo.query('div[id^="GridNode_"]').forEach(function(node, index, arr) { dijit.byId(node.id).resize(); }); old post
    • 嗯,反正基本思路就是调用resize函数让网格重新计算它的大小。我认为dojo.connect 应该可以工作,因为我之前在选项卡容器的选项卡窗格中做过同样的事情。也许dijit.layout.AccordionPane 不同。
    【解决方案2】:

    我认为 Alex Cheng 说的是正确的。以下更改可能会解决此问题。

    <div id="grid1Node" style="height:100%"></div>
    <div id="grid2Node" style="height:100%"></div>
    

    为 Grid dom 节点的容器应用高度。

    【讨论】:

    • 添加 heights 属性并没有太大帮助,但是做一个 resize() 对我有用。请参阅上面我对 Alex 的回复。感谢您的宝贵时间。
    【解决方案3】:

    另一种解决方案是使用绝对(非动态)高度设置,例如:

    <div id="grid1Node" style="height:100px"></div>
    <div id="grid2Node" style="height:100px"></div>
    

    【讨论】:

      猜你喜欢
      • 2013-01-20
      • 1970-01-01
      • 2013-09-22
      • 1970-01-01
      • 2015-09-19
      • 2019-05-15
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多