views:

48

answers:

3

Hello Stackers,

This is not an AJAX request/response callback question...

I am building a grid using Dojo 1.5. I am trying to dojo.connect expand/contract buttons with a function. My problem is that the grid.startup() method seems to take a while after being called before the actual DOM nodes are created, so when I call dojo.query none of the DOM nodes I want to connect events and handlers to are present.

I have the grid being created inside an init() method, which is called by dojo.addOnLoad(). I have the connectExpandos() method connected to init() via dojo.connect("init", connectExpandos); This executes fine, but I need to setTimeout() within a while loop to wait for the grid.startup() to finish...

Anyone aware of a better way to do this? Perhaps a grid.startup() callback I can hook onto? Thanks for any ideas. -robbie

A: 

I think you can just connect an event to grid startup method

dojo.connect(grid, "startup", function(){connectExpandos()})
virsir
It seems that connectExpandos fires before startup is finished, even with that modification. I don't think dojo.connect waits for a function to complete before the event is fired... but I may be wrong. Dojo documentation says it "Connects method to event, so that after event fires, method does too. All connected functions are passed the same arguments as the event function was initially called with. You may connect as many methods to event as needed." --This doesn't mention which part of a function execution stage is considered the event.
Robbie
A: 

You could try creating the widget programatically (assuming you are not already), then just call your method after you call startup() (It seems odd to call startup() manually, but the example it shows in the source comments show calling grid.startup() manually).

<script type="text/javascript">
   var grid = new dojox.grid.EnhancedGrid({plugins : {nestedSorting: true, dnd: true, indirectSelection: true, 
   menus:{headerMenu:"headerMenuId", rowMenu:"rowMenuId",  cellMenu:"cellMenuId",selectedRegionMenu:"selectedRegionMenuId"}},
   ... }, dojo.byId('gridDiv'));
   grid.startup();
   connectExpandos();
</script>
JasonStoltz
Jason, thanks for the answer - this was what I was doing - startup() was not finished creating the DOM nodes by the time the dojo.query in connectExpandos ran. Next time I will display some code...
Robbie
A: 

Another suggestion... it looks like the "startup" function, which is implemented in DataGrid's super class, _Grid (http://svn.dojotoolkit.org/src/dojox/trunk/grid/Grid.js), calls a function called render, which i believe is what actually render's the contents of the Grid. Subsequently, it looks like render calls a method "postrender" after it has finished rendering. Perhaps you could connect your method to the "postrender" method instead of "startup".

dojo.connect(grid, "postrender", function(){connectExpandos()})
JasonStoltz