Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Adriano Fabri 469 posts 1633 karma points
    May 30, 2017 @ 16:42
    Adriano Fabri
    0

    How to sync tree in a custom section to select current treenode?

    Hi to all,

    I'm trying to sync the tree in my custom section and select the menu item, when I open the edit page by url (without click on the tree nodes).

    I tried this code in my controller, but nothing happened (no errors also in console)...the tree is always collapsed:

    function LogsDBManagerController($route, $scope, $routeParams, $filter, hkLogsResource, userService, notificationsService, localizationService, dialogService, navigationService) {
        // Set a property on the scope equal to the current route id
        $scope.id = $routeParams.id;
    
        navigationService.syncTree({ tree: 'housekeeping', path: [-1], forceReload: false, activate: true });
    

    I think there is an error with the path...

    Can anyone help me?

  • Adriano Fabri 469 posts 1633 karma points
    Nov 06, 2017 @ 11:49
    Adriano Fabri
    0

    I already not solve this problem...anyone can help me?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 06, 2017 @ 12:55
    Dan Diplo
    0

    You need the Id of your current page in the path part of the syncTree arguments. Something like:

    navigationService.syncTree({ tree: 'housekeeping', path: [-1, $routeParams.id], forceReload: false, activate: true });
    

    Also check the first argument - tree - is the correct name you have given to your tree.

  • Adriano Fabri 469 posts 1633 karma points
    Nov 06, 2017 @ 14:41
    Adriano Fabri
    0

    Thanks Dan, but this works fine if my tree have only one level, but if I have more levels it doesn't function.

    There is a method that can retrieve the current (full) path from $routeParams.id?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 06, 2017 @ 19:22
    Dan Diplo
    0

    Not as far as I know. You have to build the path array up manually, working backward to the root node (-1).

    There is a hack you could try that is highlighted in this post - it auto-selects any node, but doesn't work with a full page reload. Might give you some ideas, though.

  • Adriano Fabri 469 posts 1633 karma points
    Nov 07, 2017 @ 08:58
    Adriano Fabri
    0

    Yeah, I just tried the solution shown in this post but not ever work. Fortunately my tree is very easy (only two levels), so I can resolve manually without any recursive loops, but in a more complex tree with over three levels this simple solution would be impossible to use.

    Unfortunately I'm not an AngularJS expert so I searched for a smart and already working solution.

    Thank you for your help ;-)

  • Streety 358 posts 568 karma points
    Jan 23, 2018 @ 09:28
    Streety
    1

    OK the documentation is rather thin.

    I think this is how it works. The navigationService.syncTree takes a bunch of parameters:

    Tree: which you can get from your $routeParams.tree;

    Path: This is an array. I think the logic is that the tree wants to know the part of the tree to show and to highlight the new item (say). This worked when I inserted the nodeID for the parent and the current node. eg: path: [ ParentTreeNodeItem, TreeNodeItem ]

    The current tree node item won't be in routeParams if the item is new. In that case I get the current item from the return model on my AJAX call. The Path array is asking for the parent to open and the child to be selected.

    Both these IDs for me are ints but they could be whatever you define them as.

    The other params are set fine.

    Hope that helps

Please Sign in or register to post replies

Write your reply to:

Draft