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 });
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.
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.
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.
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:
I think there is an error with the path...
Can anyone help me?
I already not solve this problem...anyone can help me?
You need the Id of your current page in the path part of the syncTree arguments. Something like:
Also check the first argument - tree - is the correct name you have given to your tree.
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?
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.
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 ;-)
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
is working on a reply...