PDA

View Full Version : How to disable ajax request each time expend tree node?



korndeang
27 Jun 2013, 9:07 PM
Hi all, i got stuck with tree expand, when click expand node it shows ajax request to server each time.
How to stop? because first time load i collect all. also i want expand all children too ( no need request server).
i have try set
expanded:true = true all children it will many requests to server loading at the same time :(

slemmon
1 Jul 2013, 2:25 PM
For each node that shouldn't expand are you configuring the node with leaf: true?
For each node that is not a leaf that has children: [] are you also configuring expanded: true?

If that doesn't get you going in the right direction can you post an example of what you're sending back from your server for the tree nodes when you pass back all data?

korndeang
1 Jul 2013, 5:29 PM
Thanks it works fine, my json forget leaf: true/false
[Sorry here is my suggestion why this forum auto expired session in a short time, some time lost session in 1 minute]

Misiu
21 Jul 2013, 11:20 PM
I have similar problem:
I've declared my treeStore like this:


Ext.define('Urlopy.Store.EmployeesTree', {
extend: "Sch.data.ResourceTreeStore",
requires: ['Urlopy.Model.Employee'],
model: 'Urlopy.Model.Employee',
autoLoad: false,
autoSync: true,
batch: false,
proxy: {
type: 'rest',
sortParam: false,
noCache: false, //to remove param "_dc"
url: window.appUrl + 'api/EmployeesTree',
reader: {
type: 'json',
root: 'Children'
},
writer: {
type: 'json'
}
},
folderSort: true
});

Inside my application everything works fine, all results are showing correctly.

My tree structure presents departments and employees, initially I have tree collapsed (every folder has expanded set to false).

I would like to avoid ajax request every time someone is expanding or collapsing that node. All of my data comes with first request.

I'm also using CellEditing plugin, but I'm doing edits only for employees (leafs).


Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
beforeedit: function (editor, e) {
return e.record.get('leaf');
}
}
}
So sometimes I need to be able to write something to server.

I want to disable request only when expand/collapse changed.
Is this possible? There is beforesync event in treestore, but can it be used in this scenario?

korndeang
21 Jul 2013, 11:39 PM
Could u mention on json leaf: true/false

lechenique
25 Sep 2013, 10:48 AM
In my experience, I have noticed that you have to be careful on the relation 'leaf' / 'children' in your JSON node definition.
For a given node, there can be four permutations between 'leaf': true/false and 'children': defined/ not defined

1) leaf = true , children exist
Node render as leaf (not expandable) and children are ignored.

2) leaf = true , children null
Node render as leaf (not expandable)

3) leaf = false or not defined , children exist
Node render as expandable. It DOESN'T fire an AJAX call because the children are already defined.

4) leaf = false or not defined, children null
Here is where the tree fires an AJAX call in an attempt (I guess) to discover the children that have not been defined in your JSON



Therefore, I assume that if you are getting the expansion of a node firing an AJAX call every time, you must have case 4) somewhere in your tree data.

There might be a configuration property to modify this behavior (especially for 4) ), but I am not aware of it.

neyman
17 Dec 2013, 11:54 AM
I had a similar problem to this, and solved it by simply defining an empty "children" property in each of the nodes that did not have any children. At the start I only defined that property if children existed, and I found the tree was hitting my server every time I expanded those nodes. This solved my problem.

Leshicus
12 Nov 2014, 3:42 AM
Also I would add, that I came across this, when set the root node by that manner:

{
success: true,
rows: [
{
?hildren: [
{...},
{...}
]
},
{
?hildren: [
{...},
{...}
]
}
]
}
And resolved an issue, when changed 'rows' to 'children'