PDA

View Full Version : [FIXED] 4.2 Error with locking tree grid



mankz
18 Apr 2013, 11:55 AM
Render, hit button to reload store. Then again.


Ext.onReady(function () {
Ext.define('foo', { extend : 'Ext.data.Model', fields : ['Name', 'Id'], idProperty : 'Id' })

var store = Ext.create("Ext.data.TreeStore", {
model : 'foo',
proxy : {
type : 'ajax',
method : 'GET',
url : 'tasks.js'
},
root : {
name : 'ROOOOOOOOT',
expanded : true
}
});

var g = Ext.create("Ext.tree.Panel", {
renderTo : document.body,
width : 600,
height : 400,
store : store,
columns : [
{
xtype : 'treecolumn',
header : 'Tasks',
dataIndex : 'Name',
locked : true,
width : 200
},
{
width : 200,
dataIndex : 'Id'
}
],

tbar : [
{
text : 'Refresh',
handler : function () {
store.load();
}
}
]
});
});




tasks.js

[ { "BaselineEndDate" : "2010-02-01",
"Id" : 1,
"Name" : "Planning",
"PercentDone" : 50,
"StartDate" : "2010-01-18",
"BaselineStartDate" : "2010-01-13",
"Duration" : 11,
"expanded" : true,
"TaskType" : "Important",
"children" : [
{
"BaselineEndDate" : "2010-01-28",
"Id" : 11,
"leaf" : true,
"Name" : "Investigate",
"PercentDone" : 50,
"TaskType" : "LowPrio",
"StartDate" : "2010-01-18",
"BaselineStartDate" : "2010-01-20",
"Duration" : 10
},
{
"BaselineEndDate" : "2010-02-01",
"Id" : 12,
"leaf" : true,
"Name" : "Assign resources",
"PercentDone" : 50,
"StartDate" : "2010-01-18",
"BaselineStartDate" : "2010-01-25",
"Duration" : 10
},
{
"BaselineEndDate" : "2010-02-01",
"Id" : 13,
"leaf" : true,
"Name" : "Gather documents (not resizable)",
"Resizable" : false,
"PercentDone" : 50,
"StartDate" : "2010-01-18",
"BaselineStartDate" : "2010-01-25",
"Duration" : 10
},
{
"BaselineEndDate" : "2010-02-04",
"Id" : 17,
"leaf" : true,
"Name" : "Report to management",
"TaskType" : "Important",
"PercentDone" : 0,
"StartDate" : "2010-02-02",
"BaselineStartDate" : "2010-02-04",
"Duration" : 0
}
]
}]

slemmon
18 Apr 2013, 12:31 PM
Thanks for the report! I have opened a bug in our bug tracker.

Animal
17 May 2013, 7:59 AM
Hej Mats,

It's an interesting problem. What does loading a TreeStore mean?

Because expanding a node which has no raw childNodes configured causes a load of the child nodes of that node. It's not something you should usually call.

What you are suggesting is that



load === remove all nodes from root node, set its loaded flag to false, collapse it, and call rootNode.expand();


If you change your handler to



handler : function () {
var r = tree.getRootNode();
r.set('loaded', false);
r.removeAll();
r.collapse();
r.expand();
}


You get the result you want.

Animal
17 May 2013, 9:56 AM
But try this:



Ext.override(Ext.data.TreeStore, {
load: function(options) {
options = options || {};
options.params = options.params || {};

var me = this,
node = options.node || me.tree.getRootNode(),
callback = options.callback,
scope = options.scope;

// If there is not a node it means the user hasnt defined a rootnode yet. In this case let's just
// create one for them.
if (!node) {
node = me.setRootNode({
expanded: true
}, true);
}

// If the node we are loading was expanded, we have to expand it after the load
if (node.data.expanded) {
node.data.expanded = false;
options.callback = function() {

// If newly loaded nodes are to be added to the existing child node set, then we have to collapse
// first so that they get removed from the NodeStore, and the subsequent expand will reveal the
// newly augmented child node set.
if (!me.clearOnLoad) {
node.collapse();
}
node.expand();

// Call the original callback (if any)
Ext.callback(callback, scope, arguments);
}
}

// Assign the ID of the Operation so that a ServerProxy can set its idParam parameter,
// or a REST proxy can create the correct URL
options.id = node.getId();

if (me.clearOnLoad) {
if(me.clearRemovedOnLoad) {
// clear from the removed array any nodes that were descendants of the node being reloaded so that they do not get saved on next sync.
me.clearRemoved(node);
}
// temporarily remove the onNodeRemove event listener so that when removeAll is called, the removed nodes do not get added to the removed array
me.tree.un('remove', me.onNodeRemove, me);
// remove all the nodes
node.removeAll(false);
// reattach the onNodeRemove listener
me.tree.on('remove', me.onNodeRemove, me);
}

Ext.applyIf(options, {
node: node
});

me.callParent([options]);

if (me.loading && node) {
node.set('loading', true);
}

return me;
}
});