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

The tree structure breaks when the parents and childs are not in ascending order. #9

Open
lavesh01 opened this issue Jul 19, 2023 · 2 comments

Comments

@lavesh01
Copy link

lavesh01 commented Jul 19, 2023

In my project, I am using this plugin but when I integrated the tree structure data with my database such that the data is also saved in the MySQL database to save the id, parent, level, title and return me the saved tree structure when I reload the page but when I refresh the page the tree structure breaks, It is because now the parent and child are not one after another in a structured format from top to bottom , i.e random for every branch and not in ascending order.

The data structure should be in ascending order of the parents and childs otherwise the tree breaks !!!
But it's not possible because parents, childs and siblings of the tree is created randomly and when we drag and drop the tree structure will differ, hence the tree breaks .

@ahamed
Copy link
Owner

ahamed commented Jul 19, 2023

Hi,
could you share the data you are fetching from the database and your implementation, please? I hope I could help you.

thanks.

@lavesh01
Copy link
Author

I have updated my issue please have you look !
For simplicity lets take this array , In id : 8 (Branch 8), though its parent_id is 7 and level : 2 it gets under the id: 4 element i.e Branch 4 . Why does the tree structure breaks ?
Expected Behaviour should be that the id: 8 element gets attached to it's parent_id : 7 i.e Branch 7

const dataLeft = [
    {
        id: 1,
        parent_id: 0,
        title: 'Branch 1',
        level: 1,
    },
    {
        id: 2,
        parent_id: 1,
        title: 'Branch 2',
        level: 2,
    },
    {
        id: 3,
        parent_id: 1,
        title: 'Branch 3',
        level: 2,
    },
    {
        id: 4,
        parent_id: 0,
        title: 'Branch 4',
        level: 1,
    },
    {
        id: 8,
        parent_id: 7,
        title: 'Branch 8',
        level: 2,
    },
    {
        id: 5,
        parent_id: 4,
        title: 'Branch 5',
        level: 2,
    },
    {
        id: 6,
        parent_id: 4,
        title: 'Branch 6',
        level: 2,
    },
    {
        id: 7,
        parent_id: 0,
        title: 'Branch 7',
        level: 1,
    },
    {
        id: 9,
        parent_id: 7,
        title: 'Branch 9',
        level: 2,
    }
];

@lavesh01 lavesh01 changed the title The tree structure breaks when the id's not in ascending order. The tree structure breaks when the parents and childs are not in ascending order. Jul 20, 2023
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

2 participants