Quantcast

Sorting Tree

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Sorting Tree

iceball12
I have a tree that is created using an already sorted
store.
However during tree creating some nodes get moved from on node to another node and therefore are no longer sorted correctly.
How can i get the tree to either sort the internal structure manualy or whenever i pasteItem on the model/datastore?
I did find that you can sort the store items that you get with store.fetch however i cant see how to connect a sort to the tree.
the tree has to use a .fetch somewhere? do i need to connect a sort on that fetch somehow?
Kind regards,
Willem Peters


New Windows 7: Simplify what you do everyday. Find the right PC for you.
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

Bill Keese
Tree has two methods of dropping:
    1) specifying the exact position of a node by dropping it before/after another node
    2) drop a node onto another node (making it a child of that drop target)

Sounds like you are doing the second one, and want it to get put in the sorted position rather than at the end.

You'll need to override TreeStoreModel.pasteItem to figure out the insertIndex you want.

Willem peters wrote:
I have a tree that is created using an already sorted
store.
However during tree creating some nodes get moved from on node to another node and therefore are no longer sorted correctly.
How can i get the tree to either sort the internal structure manualy or whenever i pasteItem on the model/datastore?
I did find that you can sort the store items that you get with store.fetch however i cant see how to connect a sort to the tree.
the tree has to use a .fetch somewhere? do i need to connect a sort on that fetch somehow?
Kind regards,
Willem Peters

New Windows 7: Simplify what you do everyday. Find the right PC for you.

_______________________________________________ FAQ: http://dojotoolkit.org/support/faq Book: http://docs.dojocampus.org [hidden email] http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

iceball12
i create and move nodes in code. there is no DND controller involved.

I figures out how to get this going for nodes that are created with model.newItem or pasted with model.pasteItem that have a normale node as a parent in the tree.
However for top level nodes which as parent have the root (which is invisible as i am using ForestTreeModel) the pasteItem and newItem seem to never use the insertIndex argument?
the same function use insertIndex when i debug it but when the parent == root then it simply skips the insertIndex part.

Which is weird and why should newItem or pasteItem work different for root = parent and root != parent?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

Bill Keese
If you're familiar with SQL/relational databases then you'll know that
items in a database have no implicit order.  Rather, an app can specify
an order on the query.

That's how ForestStoreModel works, it does a query with a sort clause.

Look at _requeryTop(), ForestStore by default calls that function when a
root item is added, to find out the order.

iceball12 wrote:

> i create and move nodes in code. there is no DND controller involved.
>
> I figures out how to get this going for nodes that are created with
> model.newItem or pasted with model.pasteItem that have a normale node as a
> parent in the tree.
> However for top level nodes which as parent have the root (which is
> invisible as i am using ForestTreeModel) the pasteItem and newItem seem to
> never use the insertIndex argument?
> the same function use insertIndex when i debug it but when the parent ==
> root then it simply skips the insertIndex part.
>
> Which is weird and why should newItem or pasteItem work different for root =
> parent and root != parent?
>  

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

iceball12
I do understand but why is there a difference between items with a parent as root and other items?

So for root items i need to override the requerytop to define my own sorting on the top level items?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

Bill Keese
The difference is between items with a parent and items without a
parent.   There is no "root" as far the dojo.data store is concerned.


iceball12 wrote:
> I do understand but why is there a difference between items with a parent as
> root and other items?
>
> So for root items i need to override the requerytop to define my own sorting
> on the top level items?
>
>  

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

iceball12
I need to override this function of the forestmodel if i want to determine the order in which the children of the root will be defined?

I dont think i can just use the qeury argument because i need to do a sort on the key of the children but it also has 1 exception that 1 specific child should always be the bottom node in the tree

How about overriding and then adding a sort on the key at this.store.fetch()
and then manually change the index of the specific child in the newchildren array?

_requeryTop: function(){
1342                // reruns the query for the children of the root node,
1343                // sending out an onSet notification if those children have changed
1344                var oldChildren = this.root.children || [];
1345                this.store.fetch({
1346                        query: this.query,
1347                        onComplete: dojo.hitch(this, function(newChildren){
1348                                this.root.children = newChildren;
1349
1350                                // If the list of children or the order of children has changed...    
1351                                if(oldChildren.length != newChildren.length ||
1352                                        dojo.some(oldChildren, function(item, idx){ return newChildren[idx] != item;})){
1353                                        this.onChildrenChange(this.root, newChildren);
1354                                }
1355                        })
1356                });
1357        },
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

Bill Keese
That sounds good, although I'm not sure why you have that one
exception.    Have you thought about what will happen when the users
logs out of your application and then logs back in?   At that point
where will the "exception" node appear relative to it's siblings?

Tree was meant as a view, reflecting the data in the data store and not
storing any local state information, other than which TreeNodes are
opened and which are closed.   Sounds like you want it to have some
other state too, based on which node was recently dropped?

iceball12 wrote:

> I need to override this function of the forestmodel if i want to determine
> the order in which the children of the root will be defined?
>
> I dont think i can just use the qeury argument because i need to do a sort
> on the key of the children but it also has 1 exception that 1 specific child
> should always be the bottom node in the tree
>
> How about overriding and then adding a sort on the key at this.store.fetch()
> and then manually change the index of the specific child in the newchildren
> array?
>
> _requeryTop: function(){
> 1342                // reruns the query for the children of the root node,
> 1343                // sending out an onSet notification if those children
> have changed
> 1344                var oldChildren = this.root.children || [];
> 1345                this.store.fetch({
> 1346                        query: this.query,
> 1347                        onComplete: dojo.hitch(this,
> function(newChildren){
> 1348                                this.root.children = newChildren;
> 1349
> 1350                                // If the list of children or the order
> of children has changed...    
> 1351                                if(oldChildren.length !=
> newChildren.length ||
> 1352                                        dojo.some(oldChildren,
> function(item, idx){ return newChildren[idx] != item;})){
> 1353                                      
> this.onChildrenChange(this.root, newChildren);
> 1354                                }
> 1355                        })
> 1356                });
> 1357        },
>  

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

iceball12
the exception node is always visible, the tree is used for a chat app and the exception node is a node with users that are offline, so it can just be at the bottom of the tree , the other groups should be sorted by name.
Group A
Group B
Group C
Offline

Etc...
Group A..Xx will disapppear and appear when people go offline and online.
I am connected with a Cometd ( not Dojo , websync of frozenmountain ) server.
So when the groups are created and deleted the tree should stay sorted ( which it now is for users which are children of the group A ..xxx nodes but the group nodes are not.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

Bill Keese
OK, so then you need offline to appear as the last node in the tree, even before the user has done any DnD (or there have been any updates to the Tree), so I guess you need to modify your model's getChildren() method.

On Fri, Feb 19, 2010 at 8:16 AM, iceball12 <[hidden email]> wrote:

the exception node is always visible, the tree is used for a chat app and the
exception node is a node with users that are offline, so it can just be at
the bottom of the tree , the other groups should be sorted by name.
Group A
Group B
Group C
Offline

Etc...
Group A..Xx will disapppear and appear when people go offline and online.
I am connected with a Cometd ( not Dojo , websync of frozenmountain )
server.
So when the groups are created and deleted the tree should stay sorted (
which it now is for users which are children of the group A ..xxx nodes but
the group nodes are not.
--
View this message in context: http://n3.nabble.com/Sorting-Tree-tp192214p216384.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

iceball12
i will try that on monday!
btw do you know of any problem with the tree regarding expanding?
Sometimes it seems that the node is expanded (- xx instead of + xx ) but the children are nog showing.
So i need to click twice to see the children again..
I auto expand all nodes from code and this usually works except for the first group and child in a new tree
(I generate chat room tabs with new tree for users that have joined the room)
The first group and child always show as - Group x but does not show the child node.
Still using 1.3.2 version though
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

Bill Keese
I haven't heard of that "expanding" problem, if you can make a test case
then please file a ticket and attach it, using the "attach file"
button.   (Unless it's already fixed in 1.4.)

iceball12 wrote:

> i will try that on monday!
> btw do you know of any problem with the tree regarding expanding?
> Sometimes it seems that the node is expanded (- xx instead of + xx ) but the
> children are nog showing.
> So i need to click twice to see the children again..
> I auto expand all nodes from code and this usually works except for the
> first group and child in a new tree
> (I generate chat room tabs with new tree for users that have joined the
> room)
> The first group and child always show as - Group x but does not show the
> child node.
> Still using 1.3.2 version though
>  

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting Tree

iceball12
I have got i working now!
overriding the requertytop function of the forestmodel with  the function below.
However somehow the tree thinks that the children that have changed position by the qeurytop function have had been selected.
So they are now selected after requerytop and have .class TreeNodeSelected and attribute aria-selected = true.
I cannot figure why he does that also not how i can unselect from code.

// reruns the query for the children of the root node,
    // sending out an onSet notification if those children have changed
    var oldChildren = this.root.children || [];
    var sortAttributes = [{
        attribute: "name",
        descending: false
    }];
   
    // sort by name value
    this.store.fetch({
        query: this.query,
        sort: sortAttributes,
        onComplete: dojo.hitch(this, function(newChildren){
            dojo.forEach(newChildren, function(child, index){
                // find Offline group
                if (child.key == "Offline") {
                    this.offLineIndex = index;
                   
                }
            }, this);
            if (this.offLineIndex != undefined && this.offLineIndex != newChildren.length - 1) {
                // create new children list based on sorting and Moving Offling group to bottom
                console.log("Custom Sorting Activated");
                var sortedChildren = [];
                for (var i = 0; i < this.offLineIndex; i++) {
                    sortedChildren[i] = newChildren[i];
                }
                for (var j = this.offLineIndex + 1; j < newChildren.length; j++) {
                    sortedChildren[sortedChildren.length] = newChildren[j];
                }
                sortedChildren[sortedChildren.length] = newChildren[this.offLineIndex];
               
                newChildren = sortedChildren;
            }
           
            this.root.children = newChildren;
            this.offLineIndex = undefined;
           
            // If the list of children or the order of children has changed...
            if (oldChildren.length != newChildren.length ||
            dojo.some(oldChildren, function(item, idx){
                return newChildren[idx] != item;
            })) {
                this.onChildrenChange(this.root, newChildren);
            }
        })
    });
Loading...