eu81273 / angular.treeview

AngularJS based Treeview (no jQuery)
MIT License
405 stars 223 forks source link

Highlight a selected Node from controller #33

Open schitupolu opened 10 years ago

schitupolu commented 10 years ago

Hi,

I would like to highlight a selected a node.

Though i am able to select it, but i am not able to highlight the selected node.

Below is the link for the fiddle. http://jsfiddle.net/btrz76s2/

Can someone please provide inputs on how to highlight a node?

Thanks

schitupolu commented 10 years ago

Just to add more about the fiddle.. i created an object in the ELSE block of $watch.. to keep it simple..

abhishek-g commented 9 years ago

Just add selected:"selected" to the node that you want to pre select.

haches commented 9 years ago

Adding

selected:"selected"

works to pre-select a node. However, when clicking on a different node, both nodes will be selected.

I've added the following in the link function of the angular.treeview.js to have the root node selected by default:

//check tree id, tree model
if( treeId && treeModel ) {

   // existing code

   //new code: if we have a root node, select it by default            
   if(scope[treeModel][0]) {
      scope[treeId].selectNodeLabel(scope[treeModel][0]);
   }
Amenel commented 8 years ago

I've finally succeeded in doing this while avoiding that unwanted dual selection. There's actually no need to modify the directive.

I'm using this treeview directive wrapped in another directive that adds action buttons to the right of this one.

That's all it takes. I still believe that the developer should have dealt with this use case in the Readme.

Cheers!