Dojo

Dgrid getChilldren asyncronous call to server


#1

We are trying to implement a dgrid that supports lazy loading (asynchronous) of children nodes (when a parent is expanded to call a server method to bring its childrens).
We tried overriding the getChildren method of dstore/Tree but this seems to be synchronous.
Is there a workaround?


#2

This is one of those problems that has been difficult to get right generally, but is possible to override yourself should you know your specific use case. https://github.com/SitePen/dgrid/issues/115 was the original issue and there are other issues linked to it that discuss some of the pros and cons. It may be worth opening a new issue to consider revisiting this.


#3

Hello!
I agree, mayHaveChildren must be asynchronous. But what about getChildren? Maybe I don’t understand mechanism of creation REST tree with dgrid? All samples on the Internet show only base using of MemoryStore tree, but I will load childrens asynchronously. This code not working:

define([
    "dojo/_base/declare",
    "dstore/Store",
    "dstore/Rest",
    "dstore/Tree"
], function(declare, Store, Rest, Tree) {
    return ("app.AbonentsStore", [Store, Rest, Tree], {
        target: "/api/abonents/",

        mayHaveChildren: function(object) {
            return object.hasOwnProperty("hasChildren")
                ? object.hasChildren
                : true;
        },

        getChildren: function(parent, onComplete) {
        // Who must be return server for correct working this function?
            this.get(this.getIdentity(parent)).then(function(fullObject) {
                // onComplete? Who call this function?
                onComplete(fullObject.children);
            });
        }
    });
});