Dojox.grid.DataGrid - in a widget - only renders on visible tab

冷暖自知 提交于 2019-12-04 11:28:20

Yeah, that's a big problem with the grid. If you use it declaritively in a tab container, it won't render properly on the non-visible tabs. It needs to calculate height/width (even though you specify them)...as you have seen.

The way I got around it was to create the grids programatically on tab select. I posted about my solution on the dojo forums. My code sample is over on github. It's a bit too large to post here methinks. Let me know if you want it, and i'll edit my answer.

There's also a discussion on nabble with a different solution.

"resize" works like a charm! Been looking for this for a long time (didn't know what I had to search for), thanks.

I use this routine to dynamically determine if the tab has more than one datagrid, as I may not know the ID of one single grid, maybe someone else might use that, too:

  dojo.query('div#container div[id^="gridNode_"]').forEach(function(node, index, arr) {
    dijit.byId(node.id).resize();
  });

This will check the div with id="container" (skip that part if you want to search the whole DOM) for divs with an id starting with "gridNode_" and apply "resize" to those widgets.

An alternate approach is to resize the grid upon tab element selection. Sample code

dojo.connect(dijit.byId('my_tab_container'), "selectChild", function(child){

        // if second tab (could be any...) selected
        if(child.id == 'mySecondTabId'){
            var myGrid = dijit.byId('myGridInsideTabId');
            if(myGrid != null) myGrid.resize();
        }
    });
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!