9

I want to deselect (remove selected element ).I am using jstree in my demo .So I read the plugin api . http://www.jstree.com/api/#/?f=deselect_all([supress_event]). But it not deleselect the selected item. I follow the these steps 1) Click the "b" node.then "b" node is selected. 2) Then press "deselect" button but it not deselect the items.

$('#deselect').click(function(){

    alert('--')
    $('#tree').deselect_all(true)

})

http://jsfiddle.net/fuu94/150/

Se0ng11
  • 2,303
  • 2
  • 26
  • 45
  • i used easyui plugin if u want try this....http://www.jeasyui.com/tutorial/tree/tree4.php – vivek May 19 '14 at 06:23

3 Answers3

20

Try this code:

$('#tree').jstree("deselect_all");

Insted of

$('#tree').deselect_all(true)

Here is Updated fiddle

Manwal
  • 23,450
  • 12
  • 63
  • 93
  • http://jsfiddle.net/fuu94/153/ .In this fiddle I am using functionality of go one level up –  May 19 '14 at 06:21
  • I need to disable button when It is on top . –  May 19 '14 at 06:22
  • I follow the steps 1) I expand "b" node select "b-a" node.Then click "open level button".It goes to "b".but then I click again it don't do anything .it should become disable –  May 19 '14 at 06:24
1

I just learned that you can also use:

$('#tree').jstree("deselect_all", true);

This will suppress the 'changed.jstree' event, which is what I needed for my page, and seems to be more along the lines of your original logic.

My working code excerpt verbatim:

function DeselectTree() {
    $('[id ^= "forms-foldertree-"]').each(function () {
        $(this).jstree('deselect_all', true);
    });
}
EspressoBeans
  • 1,747
  • 12
  • 22
0

What I use,

$('#deselect').click(function(){

$('#tree').attr("checked", false);

})

or you can add custom attributes and give stylesheet/class for select/deselect

by jquery change this

$('#deselect').click(function(){

if($('#tree').attr("customattr") == "select" )

   $('#tree').attr("customattr", "unselect");

else

$('#tree').attr("customattr", "select");

})

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58