iVantage / angular-ivh-treeview

A treeview for AngularJS with filtering and checkbox support.
http://ivantage.github.io/angular-ivh-treeview/
MIT License
239 stars 89 forks source link

Error in scope or bad use of options #113

Open elaugus opened 8 years ago

elaugus commented 8 years ago

Greetings, I'm trying to automate some stuff and I'm creating many trees on runtime whose node template (nodeTpl) comes from another place.

If I create them one by one with the different options they work like a charm, but if I use them inside an ng-repeat sending the options, they only use the value in nodeTpl from the 1st iteration.

This behavior seems only to happen for this specific property, all the other properties like twistieLeafTpl, twistieExpandedTpl and onCbChange work fine.

You can see the issue at http://codepen.io/anon/pen/YqXmWm

Do I'm doing something wrong? Or it is really an error

Edit: Clarifications and Typos

jtrussell commented 8 years ago

Weird, well I see what's going on but I'll have to do some investigating.

It seems that within an ngRepeat when one of the tree nodes asks for a reference to the parent it's always getting the controller tied to the same treeview instance. Even in the ngRepeat case the second (and third etc.) treeview options are set up correctly in the treeview itself and each treeview instance initially has its own controller etc.. Might have something to do with the deferred compilation of tree nodes.... maybe.

So short answer, you're not doing anything wrong. There's something strange happening with multiple treeviews inside ngRepeat.

jkrot commented 7 years ago

So same issue different vein, when I was to have two different trees use the same data they share tree states and configs. There doesn't seem to be a way for two different trees to use the same data without affecting each other.

jtrussell commented 7 years ago

I think you're describing a different issue than the original poster. This issues is for nested tree, even with different data. It is an acknowledged issue (noted on the project README) and enough of an edge case that it's probably not going to be fixed in the near future.

In your case, @jkrot, you can use the same data for different trees you just need to use different attributes for the various tree properties. See this part of the README: https://github.com/iVantage/angular-ivh-treeview#options. You'll need to specify different attribute names for the selected, indeterminate, and/or expanded properties.

jkrot commented 7 years ago

Maybe I was mistaken but I assumed this would work. I didn't do it through the options controller I did it through the markup.

<div ivh-treeview="folder" class="treeview" ivh-treeview-expand-to-depth="0" ivh-treeview-default-selected-state="true" ivh-treeview-validate="false" ></div>

<div ivh-treeview="folder" class="treeview-list" ivh-treeview-expand-to-depth="1" ivh-treeview-default-selected-state="false" ivh-treeview-validate="true" ></div>

So I had two different treeviews which I style differently that use the same class that are in different templates. Depending on the template I believed it should have changed the configurations however the 2nd treeview inherited the 1st treeview configs.

jtrussell commented 7 years ago

That's very strange - would you mind terribly putting together a demo using the jsbin template provided in the readme? https://github.com/iVantage/angular-ivh-treeview#reporting-issues-and-getting-help

jkrot commented 7 years ago

This is super easy to replicate, http://jsbin.com/ruxedo/edit?html,js,output change the demo.stuff2 to demo.stuff1 you will see they keep the same settings even if they are different. For me I load the template on a tab click so no matter what configs I put on the two of them they share configs if the data is the same.

jkrot commented 7 years ago

I can confirm they are getting different scopes and they are getting the correct settings and both in their respective scopes are set to expandToDepth 1 or -1 however they are still showing the correct expanded tree length on load. It seems to do this with most of the settings. This seems to be that since the data is shared between two of them it just sets the property that it is expanded to be true. Any node specific property whether selected or expanded doesn't differentiate between the two.

jkrot commented 7 years ago

I tried to work around this with

var mediaNode = $filter('filter')($scope.folder, {media: true})[0];
ivhTreeviewMgr.collapse($scope.folder, mediaNode);

Which works after I am done sorting but then when I click on the other tab and load the template again with the expanded tree then it expands it again.

jkrot commented 7 years ago

Alright I see the problem here I will note this as a separate issue.

snehaRGlassbeam commented 7 years ago

Can you please provide a solution to the above problem @jkrot ? I am facing the same issue of the states to get affected with two tree views that share the same data. Thanks.