Robbie
Robbie

Reputation: 445

How to call a function (non AJAX) after another function (non AJAX) finishes in Dojo?

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?

Upvotes: 3

Views: 2224

Answers (4)

Mike N
Mike N

Reputation: 125

I think the callback you were looking for was _onFetchComplete

dojo.connect(grid,'_onFetchComplete',function(event){
    alert("hello data is loaded")
});

Upvotes: 1

JasonStoltz
JasonStoltz

Reputation: 3110

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()})

Upvotes: 3

JasonStoltz
JasonStoltz

Reputation: 3110

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>

Upvotes: 0

virsir
virsir

Reputation: 15509

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

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

Upvotes: 0

Related Questions