Deselect all selected nodes in the tree

4,207 views
Skip to first unread message

Spike

unread,
Oct 15, 2009, 5:24:30 AM10/15/09
to jsTree
In relation to another post on this forum, I want to provide a way for
the user to deselect all nodes so that they can insert a node at the
very root of the structure (the unseen parent node). I've come up with
this code, but it triggers when I actually click on a node! so I
presume clicking on the node blurs the outer DIV and causes this to
trigger:

jQuery("#eportfolios").bind("blur", function(e){
jQuery.each(t.selected_arr, function(i, val) {
t.deselect_branch(val);
})
});


#eportfolio's is the outer div.

If anyone can give me any tips on this that would be great. It seems
like it should be something that's in there by default?

Cheers,

Brendon

Spike

unread,
Oct 15, 2009, 3:54:23 PM10/15/09
to jsTree
This seems to do the trick but it feels messy:

jQuery("#eportfolios, #eportfolios li, #eportfolios ul").bind
("click", function(e){
t.deselect_branch(t.selected);
});

of course I'm only using single select mode.

vakata

unread,
Oct 20, 2009, 6:40:29 PM10/20/09
to jsTree
To insert a root you do not need to deselect everything - just pass -1
to the ref_node argument of the create function.
Cheers,
Ivan

Brendon Muir

unread,
Oct 20, 2009, 6:49:17 PM10/20/09
to jst...@googlegroups.com
That's correct, but I only want to have one "add a new item" button and want it to either add it to the currently selected parent or if nothing is selected to add it to the root. Because you can't easily unselect everything in an intuitive way (i.e. click somewhere other than on an item (like in windows) I had to implement that technique. Providing a "add to the root" button breaks so many usability rules :D

I also noticed an anomoly. When you call delete on the node in a tree that only has one node (i.e. you're about to delete the last node ever) it will delete the node and you'll be left with an empty tree. That's fine, but it seems that tree.selected still returns an element (rather than false) even though the tree is empty and nothing is selected. I've just worked around that by calling unselect(selected) in the ondelete callback after the item is deleted.

Hope all that helps, this is a great tree and is working very well for what we wanted to do. Provided I'm able to finish every feature I want to implement I'll make a donation to say thanks! :D

Cheers,

Brendon

2009/10/21 vakata <ivan.b...@gmail.com>

vakata

unread,
Oct 20, 2009, 6:59:47 PM10/20/09
to jsTree
Hi again,

as always - donations are not required but encouraged ;) I always try
to help - donation or not :)

As for the delete problem - that is fixed on my working copy, but
still - thanks for noticing.

As for deselecting, I guess you could process the click event in the
document. Then check:

if($(event.target).parents('.tree:eq(0)').size() == 0) {
jQuery.each(t.selected_arr, function(i, val) {
t.deselect_branch(val);
})
}

I have not really tested this, but it should work - also - replace t
with a tree reference - you can get one using $.tree.reference or
$.tree.focused.

This will make clicking outside the tree container or the container
itself (but not the UL) deselect all.

Kindest regards,
Ivan

On 21 Окт, 01:49, Brendon Muir <bren...@spikeinsights.co.nz> wrote:
> That's correct, but I only want to have one "add a new item" button and want
> it to either add it to the currently selected parent or if nothing is
> selected to add it to the root. Because you can't easily unselect everything
> in an intuitive way (i.e. click somewhere other than on an item (like in
> windows) I had to implement that technique. Providing a "add to the root"
> button breaks so many usability rules :D
> I also noticed an anomoly. When you call delete on the node in a tree that
> only has one node (i.e. you're about to delete the last node ever) it will
> delete the node and you'll be left with an empty tree. That's fine, but it
> seems that tree.selected still returns an element (rather than false) even
> though the tree is empty and nothing is selected. I've just worked around
> that by calling unselect(selected) in the ondelete callback after the item
> is deleted.
>
> Hope all that helps, this is a great tree and is working very well for what
> we wanted to do. Provided I'm able to finish every feature I want to
> implement I'll make a donation to say thanks! :D
>
> Cheers,
>
> Brendon
>
> 2009/10/21 vakata <ivan.bozha...@gmail.com>

Brendon Muir

unread,
Oct 20, 2009, 7:02:55 PM10/20/09
to jst...@googlegroups.com
Thanks Ivan :) I'll work that into what I've got going now :D

Cheers,

Brendon

2009/10/21 vakata <ivan.b...@gmail.com>

Brendon Muir

unread,
Oct 20, 2009, 10:02:09 PM10/20/09
to jst...@googlegroups.com
Hi Ivan, I've also noticed that TREE_OBJ.rollback(RB); doesn't do anything in the oncreate callback. Just checking if this is a problem or just that I'm calling it wrong?

Cheers,

Brendon

2009/10/21 Brendon Muir <bre...@spikeinsights.co.nz>

vakata

unread,
Oct 21, 2009, 1:33:35 AM10/21/09
to jsTree
Well, actually it should remove the node that was added. I will check
into it. Still - 1.0-beta has create completely rewritten, so the
behavior is a bit different.

Cheers,
Ivan

On 21 Окт, 05:02, Brendon Muir <bren...@spikeinsights.co.nz> wrote:
> Hi Ivan, I've also noticed that TREE_OBJ.rollback(RB); doesn't do anything
> in the oncreate callback. Just checking if this is a problem or just that
> I'm calling it wrong?
> Cheers,
>
> Brendon
>
> 2009/10/21 Brendon Muir <bren...@spikeinsights.co.nz>
>
> > Thanks Ivan :) I'll work that into what I've got going now :D
> > Cheers,
>
> > Brendon
>
> > 2009/10/21 vakata <ivan.bozha...@gmail.com>

Brendon Muir

unread,
Oct 21, 2009, 5:42:26 AM10/21/09
to jst...@googlegroups.com
Thanks Ivan :) I checked with other callbacks and it's the same. I'm using a jquery ajax call to perform a function on the server (to add or delete the node) and then roll it back if an error status is returned in the ajax call :)

2009/10/21 vakata <ivan.b...@gmail.com>

vakata

unread,
Oct 22, 2009, 8:50:33 AM10/22/09
to jsTree
Hi again,

I forgot to mention that if you are using a 0.9.9 version rollback is
invoked using:

jQuery.tree.rollback(RB);

Kindest regards,
Ivan

On 21 Окт, 12:42, Brendon Muir <bren...@spikeinsights.co.nz> wrote:
> Thanks Ivan :) I checked with other callbacks and it's the same. I'm using a
> jquery ajax call to perform a function on the server (to add or delete the
> node) and then roll it back if an error status is returned in the ajax call
> :)
>
> 2009/10/21 vakata <ivan.bozha...@gmail.com>

Brendon Muir

unread,
Oct 22, 2009, 5:44:57 PM10/22/09
to jst...@googlegroups.com
Lol, thanks so much for that :) Works great now. For some reason the ajax caller still runs the 'error' condition code even though I return a 200 status, nothing to do with your code though :) Will look into it :)

Oh and I'll just start another thread on a separate problem with Camino on the Mac :)

Cheers,

Brendon

2009/10/23 vakata <ivan.b...@gmail.com>

Spike

unread,
Oct 22, 2009, 8:02:55 PM10/22/09
to jsTree
Looks like if you tell jQuery.ajax that it is to expect json as a
return, you need to return json (even if it's an empty result) as the
datatype or you trigger the error callback. I was just returning a 200
header with no content but that doesn't seem to work :)

Hope that helps someone else :)

Cheers,

Brendon

On Oct 23, 10:44 am, Brendon Muir <bren...@spikeinsights.co.nz> wrote:
> Lol, thanks so much for that :) Works great now. For some reason the ajax
> caller still runs the 'error' condition code even though I return a 200
> status, nothing to do with your code though :) Will look into it :)
> Oh and I'll just start another thread on a separate problem with Camino on
> the Mac :)
>
> Cheers,
>
> Brendon
>
> 2009/10/23 vakata <ivan.bozha...@gmail.com>
Reply all
Reply to author
Forward
0 new messages