webanimals / dynatree

Automatically exported from code.google.com/p/dynatree
0 stars 0 forks source link

The focus(true) does not work for a node within the loadkeypath function #484

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1.) If you look at the if branch there is activated AND focused the foundNode. 
Setting the focus works fine here

2.) If you look at the else branch there happens the same as in 1.) BUT setting 
the focus on the node does NOT work!

There must be a problem with the loadkeypath function and focus because 
EVERYWHERE else in my app the focus(true) works fine.

If possible, please attach an example HTML file (e.g. a copy of `doc/_test-
ISSUE.html`), that reproduces the problem when copied
into the dynatree/doc/ folder or reproduce on jsFiddle:

Sorry more than this code I can not uploaded.

/******************* CODE ***************************************/
 $("#searchfield").autocomplete({
            select: function (event, ui) {
                var tree = $("#TreeDiv").dynatree("getTree");
                var unitId = ui.item.UnitId;
                var foundNode = tree.getNodeByKey(unitId.toString());
                if (foundNode) { // the nodes parents were already lazy loaded/expanded
                    foundNode.activate(true);
                    foundNode.focus(true);
                }
                else { // the node is not found because I have to load the node and its parent first
                    var loadkeyPath;
                    $.getJSON('@Url.Action("SelectUnits","Unit")', { unitId: unitId }, function (units) {

                        // Add the searched UnitId at the end
                        units.push(unitId);
                        loadkeyPath = units.join(';');

                        tree.loadKeyPath(loadkeyPath, function (node, status) {
                            if (status == "loaded") {
                                node.expand();
                            } else if (status == "ok") {
                                node.activate(true);
                                node.focus(true);
                                var activeLi = node.li;

                                $('#TreeDiv ul').animate({
                                    scrollTop: $(activeLi).offset().top - $('#TreeDiv ul').offset().top + $('#TreeDiv ul').scrollTop()
                                }, 'slow');

                            } else if (status == "notfound") {
                                console.log('node not found');
                            }
                        });
                    });
                }

                return false;
            },
/*********************************************************************/

What version of the dynatree and jQuery are you using?
On what operating system and browser?
What DOCTYPE declaration are you using?

dynatree version 1.2.5
jquery version 2.1
Windows 8 x64
IE11 or Chrome35

Please provide any additional information below.

My tree settings:

$('#TreeDiv').dynatree({
            onLazyRead: function (node) {
                node.appendAjax({ url: '@Url.Action("GetChildrenUnits", "Unit")', data: { "unitId": node.data.key } });
            },
            onPostInit: function (isReloading, isError) { // When the rootnode is loaded with the 1th level children the onPostInit should not be needed
                var rootnode = $("#TreeDiv").dynatree("getRoot");
                var children = rootnode.getChildren();
                var firstNode = children[0]; // The first node of the hidden dynatree rootNode is MY root node
                firstNode.toggleExpand();
                firstNode.activate(true);
                firstNode.focus(true);
            },
            keyPathSeparator: ";",
            children: data,
            activeVisible: true,
            onClick: function (node) {

            // do stuff
            },
            imagePath: '~/Content/skin/',

Original issue reported on code.google.com by bestellu...@googlemail.com on 20 Apr 2014 at 7:50

GoogleCodeExporter commented 9 years ago
I use HTML5 DocType

Original comment by bestellu...@googlemail.com on 20 Apr 2014 at 7:52

GoogleCodeExporter commented 9 years ago
I won't be able to fix this for Dynatree (unless someone sends a patch) since I 
am focused on Fancytree now.
If possible, feel free to try and open an issue there, if the problem should 
still exist.

Original comment by moo...@wwwendt.de on 23 Apr 2014 at 3:42

GoogleCodeExporter commented 9 years ago
Cleanup Scrumboard

Original comment by moo...@wwwendt.de on 2 May 2014 at 7:47