How to select node in dynatree

cashmere picture cashmere · Jun 12, 2012 · Viewed 8.3k times · Source
tree.dynatree({
        initAjax: {
            url: "../Users/GetTree"
        },
        checkbox: true,
        selectMode: 2,
        fx: { height: "toggle", duration: 200 },
        persist: true,
        clickFolderMode: 1,
        autoFocus: false,

         onClick: function (node, event) {
           ....
         }
   }    

on server side I have class TreeNode

 public class TreeNode
 { 
      .....

      public TreeItemsAttr attr { get; set; }

      public string addClass { get; set; }
 }

and class TreeItemsAttr

 public class TreeItemsAttr
{
    public string id { get; set; }

    public bool canHaveSubs { get; set; }

    public bool selectable { get; set; }

    public bool isSelected { get; set; }

    public string docDate { get; set; }
}

So, in my action I setup some tree node isSelected=true and add class addClass="dynatree-selected", but when I call node.tree.getSelectedNodes() I get [].

How can I setup on server side so the some nodes are selected?

I also try to add in TreeNode property select and setup to true, but it did not help me.

Answer

Alper picture Alper · Jul 31, 2012

In dynatree document page (In Section : 5.3 Handling selection events) there is a sample for that aim.

onSelect: function(flag, node) {
        if( ! flag )
            alert("You deselected node with title " + node.data.title);
        var selectedNodes = node.tree.getSelectedNodes();
        var selectedKeys = $.map(selectedNodes, function(node){
            return node.data.key;
        });
        alert("Selected keys: " + selectedKeys.join(", "));
    }

and the result page is : http://wwwendt.de/tech/dynatree/doc/sample-select.html

This way is working in Client side, but i think you can send selected variables to your server.