how to check dojo.datagrid loading completed? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-23 12:26:27

问题


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.


回答1:


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);




回答2:


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.




回答3:


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...    
    });
});



回答4:


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!
}


来源:https://stackoverflow.com/questions/5439275/how-to-check-dojo-datagrid-loading-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!