This question already has an answer here:
-
How to determine if a dojo grid has finished loading?
4 answers
I have a dojo.datagrid in one of my pages. Datagrid and its store(by calling an URL) are created by declarative method. not by dynamic/programmatic.
I need to execute a javascript method which displays a div(which requires few data from the datagrid) just below my datagrid. I should display the div only after my datagrid loading completed;not before that.
I am looking for event like onload completed for datagrid. Is there any event do we have with dojo.datagrid? I don't see it in the event's list of dojo.Datagrid documentation.
Is there a way to check dojo datagrid onload completed?
Is there any way to use dojo.connect to handle this?
Please let me know if we have any way to do this...
Thanks,
Raj.
The datagrid itself never actually loads all of the data available, it is only showing a sub selection of the data in its store.
You will need to tie into the store events in order to catch the onload event. Since the store can load data from lots of places, you will need to pass an onComplete function to the fetch method of the grid store.
grid.store.fetch({onComplete : function (items) { // Do something }});
You could also create the store programatically, call fetch with your onComplete listener, and once you have finished the modification of the items in the store's onComplete listener, call myGrid.setStore(myStore);
The DataGrid
has an event _onFetchComplete
which you could connect to with dojo.connect
. Note that it starts with _
though, so it's supposed to be a private/protected kind of event and its behaviour could change in newer Dojo versions. I know it works well in Dojo 1.6.
As Alex already pointed out, you can react to the (unfortunately) private _onFetchComplete
event. With dojo 1.7, this can be achieved with dojo.aspect like:
require(["dojo/aspect", "dojox/grid/DataGrid", ...], function(aspect, DataGrid, ...)
var myGrid = new DataGrid({ ... });
aspect.after(myGrid, "_onFetchComplete", function() {
// Do something with myGrid...
});
});
You can set up a timer to check if the data is loaded, run every second or so until the load is complete (setSelectedIndex will return true):
private var load_check:uint;
/* start the interval timer when the app is initialized */
protected function init ():void
{
load_check = setInterval(getTime, 500); // 1/2 second
}
private function getTime():void
{
if ( !datagrid.setSelectedIndex (0))
return;
clearInterval(load_check); // data loaded!
}