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

tree.addNode double entries #334

Closed
tbellembois opened this issue Apr 21, 2018 · 5 comments
Closed

tree.addNode double entries #334

tbellembois opened this issue Apr 21, 2018 · 5 comments

Comments

@tbellembois
Copy link

hello,
I have an issue with tree.js v1.9.6 using the addNode method.
I have double node entries created (see screenshot "new folder" nodes).
tbellembois
The first one is created under the gj-list gj-list-bootstrap gj-hidden ul, the second one under gj-list gj-list-bootstrap ul.
Here is my code:

var nodeId = tree.getSelections()[0];
...
var parent = tree.getNodeById(nodeId);
tree.expand(parent);
tree.addNode({ id: result.id, text: "new folder", url: "", hasChildren: true, lazy: true, icon: "" }, parent);
// result.id is returned from ajax

Have I missed something ?
Thanks.

@atatanasov
Copy link
Owner

I'm not able to replicate the issue. Everything seems to be working fine with with the following code sample:

<html>
<head>
    <meta charset="utf-8" />
    <title>Treeview Example</title>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
    <link href="https://cdn.jsdelivr.net/npm/gijgo@1.9.6/css/gijgo.min.css" rel="stylesheet" type="text/css">
    <script src="https://cdn.jsdelivr.net/npm/gijgo@1.9.6/js/gijgo.min.js"></script>
</head>
<body>
    <button onclick="add()">Add node1</button>
    <button onclick="tree.addNode({ Title: 'node1-1' }, tree.getNodeByText('node1'))">Add node1-1</button>
    <button onclick="alert(tree.getNodeByText('node1').html())">Get node1</button>
    <div id="tree"></div>
    <script>
        var tree;
        $(document).ready(function () {
            tree = $('#tree').tree({
                primaryKey: 'id',
                dataSource: '/Locations/Get'
            });
        });
        function add() {
            var nodeId = tree.getSelections()[0];
            var parent = tree.getNodeById(nodeId);
            tree.expand(parent);
            tree.addNode({ id: 77, text: "new folder", url: "", hasChildren: true, lazy: true, icon: "" }, parent);
        }

    </script>
</body>
</html>

Please reopen if you can provide code sample

@tbellembois
Copy link
Author

tbellembois commented May 1, 2018

hello,
Thanks for the answer. I have finally found the problem:

        // Create the tree inside the <div id="tree"> element.
        $('#tree').tree({
            primaryKey: 'id',
            dataSource: '/getBranchNodes/',
            lazyLoading: true,
        });

Turning off lazyLoading fix the problem but I can not figure out why.
I use lazy loading on my tree. Can you confirm the bug ?

atatanasov pushed a commit that referenced this issue May 2, 2018
@atatanasov
Copy link
Owner

Thanks for the additional details. I was able to replicate the issue and fix it. This is fixed just in the development version for now. You can find the development build in the dist folder at github.

@tbellembois
Copy link
Author

Thanks a lot.

@stvowi
Copy link

stvowi commented Sep 18, 2018

It happen, wenn you insert a record via ajax call which will give back a new ID before you call the content of the ADD function. The sample alone without ajax is working.

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

3 participants