Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating expanded tree nodes fails #467

Closed
ghost opened this issue Mar 6, 2013 · 1 comment
Closed

Updating expanded tree nodes fails #467

ghost opened this issue Mar 6, 2013 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 6, 2013

Attempting to update rows in grid that use 'tree' plugin encounters error if nodes are expanded, when updated. When child node is updated after parent node, tree.js (91) error encountered .

Example below calls store.put on parent object which works fine, but following store.put to child node fails with error in tree.js.

    var data = [
       {id: 0, title: "Item_0", parentId: null, hasChildren: true},
       {id: 1, title: "Item_1", parentId: 0,    hasChildren: false}
    ];

    var store = window.store = Observable(new Store({
            data: data,
            idProperty: "id",
            mayHaveChildren: function(item){
                    return item.hasChildren;
            },
            getChildren: function(item){
                    return store.query({parentId: item.id});
            }
    }));
    window.grid = new OnDemandGrid({
            store: store,
            showHeader: false,
            query: {id: 0},
    columns: {title: tree({ shouldExpand : function () { return true;}, })},
    }, "tree");

    var updater = function(index) {
        data[index].title += "_updated" ;
        store.put(data[index]) ;
    };

    setTimeout (function () {
        try { 
          updater(0) ;
          updater(1) ; // This fails with "Cannot read property 'id' of undefined"
        } catch (err) {
            alert (err.message) ; console.log(err.stack) ;
        }

    }, 5000) 
@ghost
Copy link
Author

ghost commented Mar 7, 2013

Issue seems to be in List.js. _When insertRow is called for second put/update, the rowIdToObject[id] value is not set, which cause failure elsewhere. For List.js code extract below, 'row' has a value, but 'beforeNode' has not.

if(!row || // we must create a row if it doesn't exist, or if it previously belonged to a different container
(beforeNode && row.parentNode != beforeNode.parentNode)){
if(row){// if it existed elsewhere in the DOM, we will remove it, so we can recreate it
this.removeRow(row);
}
row = this.renderRow(object, options);
row.className = (row.className || "") + " ui-state-default dgrid-row " + (i % 2 == 1 ? oddClass : evenClass);
// get the row id for easy retrieval
this._rowIdToObject[row.id = id] = object;
}

Without understanding cause of issue, the following code addition seems to prevent problem, Of course better understanding of code is needed, to determine if its a proper resolution.

else if (row && !this._rowIdToObject[id]) {
this._rowIdToObject[row.id] = row;
}

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants