Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onToggle not fired for leaf nodes #169

Open
cgatesman opened this issue Nov 28, 2016 · 14 comments
Open

onToggle not fired for leaf nodes #169

cgatesman opened this issue Nov 28, 2016 · 14 comments

Comments

@cgatesman
Copy link

cgatesman commented Nov 28, 2016

I would like to "select" leaf nodes using useCheckboxes="false". Currently onToggle is not getting called for leaf nodes. To me, it seems like it should. The handler should be the one responsible for dealing if it's a leaf or not--if that really matters.

Something more like this in ivhTreeviewToggle:

      element.bind('click', function() {
        scope.$apply(function() {
          if(!trvw.isLeaf(node)) {
            trvw.toggleExpanded(node);
          }
          trvw.onToggle(node);
        });
      });
@jtrussell
Copy link
Contributor

jtrussell commented Nov 28, 2016

@what's the use case for toggling a leaf node? Having no child nodes they cannot be expanded or collapsed. Are you really interested in just having a click callback for labels? Or perhaps you're looking to load child additional child nodes dynamically?

@cgatesman
Copy link
Author

I have several treeviews that are basically a single selection tree that drives a subview. I have the current selection highlighted when the user clicks on a node.

@cgatesman
Copy link
Author

Note, I'm using 'useCheckboxes=false'

@charles-henry
Copy link

Is there a way to have a click callback for labels? I too want to have a single selection tree. I think a click callback on labels would make that possible.

@arielcr
Copy link

arielcr commented Jan 3, 2017

Hi @charles-henry , I'm also looking for this functionality, I think it makes sense to be able to do that. Have you figure it out yet?

Or maybe @cgatesman ?

@cgatesman
Copy link
Author

@arielcr, I just patched my local copy of ivh-treeview.js with the code I have above in the ivhTreeviewToggle directive. Then you get onToggle callbacks on leaf clicks, also.

@sashberd
Copy link

sashberd commented Jan 9, 2017

@jtrussell Why not to provide option for leaf select with callback as @cgatesman asked. You will update the directive or we should do this feature manually?

@jtrussell
Copy link
Contributor

This was not implemented simply because leaf nodes cannot be expanded or collapsed by their nature :). If you'd like generic click handlers perhaps you could just use ng-click within your template?

@sashberd
Copy link

sashberd commented Jan 18, 2017

@jtrussell I will give you an example of this need, e,g, I need on leaf,parent,root clicks filter my page. For this aim I need any id of the clicked item. In current code I can get ids of all parents, but not leaf. Im not talking about to use onToggle (in my updated directive I use another event) cause you are right, it is ridicules toggle elements that could be toggled, but another solution with different event, e.g. onNeedleClick, is suitable for such directive.

@jtrussell
Copy link
Contributor

Can you accomplish this with a little directive attached to each node in your template? Something like this (untested):

app.directive('onNodeClick', function() {
  return {
    link: function(scope, element) {
      element.on('click', function() {
        scope.$emit('NODE_CLICK', scope.node);
        scope.$apply();
      })
    }
  };
});

@sashberd
Copy link

Something like you solution I had been implemented. However, in my opinion, such functionality is good feature to have. :)
If we ran out of this issue, I can close it?

@jtrussell
Copy link
Contributor

I'd be open to adding such a feature with if a PR came in with tests :). That said have you tried using the v2 branch? In that version you'll have access to your transcluded scope when using inline templates:

<div ivh-treeview="fancy.bag">
  <script type="text/ng-template">
    <div>
       <span ng-click=" ng-click="otherCtrl.clicky(node)">
         {{trvw.label(node)}}
       </span>
     <div ivh-treeview-children></div>
   </div>
  </script>
</div>

Where otherCtrl.clicky is defined in a controller outside the directive.

@sashberd
Copy link

I used v2.0.0-alpha.3.
My solution was to add function callback attribute to each leaf. I will check you suggest.
Thanks for help

@dklug-sisdam
Copy link

Hi @jtrussell I'm using v2 of treeview.js but I can't reach controller's function as your post says. Other controller is not fancy controller? maybe there is something that I'm missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants