1

This drove me crazy for a weekend, and although I found what seems to be a workable solution, my question is whether there is something fundamental about using Dojo/Dijit that I'm missing.

Here's the problem: Whenever I create page in which a dgrid uses a JsonRest store and is in a hidden tab of a TabContainer (one that is not the initially selected one), I get DOMExceptions and a somewhat screwed up dgrid. In particular, the dgrid has a large empty space under the last row of data, and scrolling to the bottom or top of the dgrid's data throws additional DOMExceptions.

If I click on one of the column headers to sort the dgrid, it resets its layout and works fine. If the dgrid initializes on a visible part of the page instead of an unselected tab, it's fine. If I use a Memory store instead of a JsonRest, everything's fine (even if the dgrid is initialized in a hidden tab). If the dgrid is initialized in a hidden tab but without a store, it's fine (but empty).

Based on the evidence, I guessed the problem had something to do with the fact that a JsonRest query takes time, and for some reason that's breaking dgrid when it's initializing. My solution was to create the dgrid without a store, and then set the store when its the tab containing the dgrid was shown. This seems kludgy, though. I should be able to create a dgrid with a store and not have to fiddle with it externally.

So, is my somewhat hack-ish solution the proper (or at least a reasonable) way to handle initializing a hidden dgrid with server-supplied data, or is there something about the setup of TabContainer+dgrid+JsonRest that I'm missing?

jason0x43
  • 3,363
  • 1
  • 16
  • 15

1 Answers1

1

I don't have an answer to your question, but there is a contract between Dijit widgets and containers regarding the lifecycle and startup of a widget... in particular, when the elements are added to the DOM and, at the end, when the startup() method is called to layout and resize the elements. dgrid probably does not participate. Perhaps you can connect something to the TabContainer's startup method which will trigger a layout of the dgrid component?

peller
  • 4,435
  • 19
  • 21
  • It would not surprise me if I was breaking a contract somewhere; the details of the Dijit lifecycle are still a bit vague to me.The dgrid is actually contained within a ContentPane. Well, to be more correct it is the ContentPane's domNode (in the CP's postCreate, I use its domNode as the attachment point for the grid, as in `var grid = declare([Grid, DijitRegistry], {...}, this.domNode)`). That appears to work insofar as the grid resizes itself as the ContentPane once the containing tab becomes selected. – jason0x43 Feb 13 '12 at 15:47