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

Disable recursive selection of child nodes #124

Closed armellarcier closed 8 years ago

armellarcier commented 8 years ago

How to make recursive selection an option? Is that possible? I can't find the code responsible for that...

Thanks in advance!

dabaaaz commented 8 years ago

+1

jtrussell commented 8 years ago

There's no explicit option for changing the baked in selection strategy. If you want simple (i.e. non-propagating) selection the easiest thing is to swap out the ivh-treeview-checkbox directive in your template with a vanilla checkbox + ngModel.

armellarcier commented 8 years ago

I found an easy solution to make that an option and created a PR #125

jtrussell commented 8 years ago

Is there a compelling reason not to use the strategy I mentioned above? Disabling your recursive selection option basically turns ivhTreeview checkboxes into regular ones (if I'm reading the changes correctly) but with more overhead and at the cost of extra complexity to the directive as a whole.

armellarcier commented 8 years ago

I needed recursive selection to be an option the user could turn on and off easily. As I'm using angular material, I'm calling the 'select' method from a custom directive with an option object with 'recursiveSelection' either true or false. I don't know if that's a compelling reason though. Just pretty straightforward.

jtrussell commented 8 years ago

Would it be possible to call ivhTreeviewMgr.select when recursive selection is desired, and if not simply set the node's selected property in your custom directive? You can grab that property name from ivhTreeviewOptions to be fully generic, as well as the indeterminate property if you need it.

jfoshee commented 8 years ago

While I agree with the OP @Benew that this would be a good feature, for completeness here are code samples for how to accomplish this via @jtrussell's suggestion.

<div ivh-treeview="...">
  <script type="text/ng-template">
        <span ng-if="trvw.useCheckboxes()">
            <input class="ivh-treeview-checkbox"
                   ng-model="node.isSelected"
                   type="checkbox">
        </span>
  </script>
</div>

Note that if you are not using the default isSelected property, you will need to bind to your particular property.

<div ivh-treeview="..."
     ivh-treeview-selected-attribute="'IsSelectedCustom'">
  <script type="text/ng-template">
        <span ng-if="trvw.useCheckboxes()">
            <input class="ivh-treeview-checkbox"
                   ng-model="node.IsSelectedCustom"
                   type="checkbox">
        </span>
  </script>
</div>