Code Monkey home page Code Monkey logo

Comments (2)

fritz-c avatar fritz-c commented on May 23, 2024 1

As all of the helper functions also use children as the key for children, I would suggest you convert it temporarily. Try this function:

const convertChildrenKeys = (children, prevKey, nextKey) => {
    return children.map(child => {
        const modifiedChild = {
            name: child.name,
            // carry over whatever other props you want
        };

        // If this child has children, add them using the nextKey
        if (child[prevKey] && child[prevKey].length > 0) {
            modifiedChild[nextKey] = convertChildrenKeys(child[prevKey], prevKey, nextKey);
        }

        return modifiedChild;
    });
};

// Convert your data to a form that can be handled by react-sortable-tree
const compatible = convertChildrenKeys(myTreeData, 'users', 'children');

// ... 

// After you're done using the library,
// convert the data back to its original format (if you need to)
const original = convertChildrenKeys(compatible, 'children', 'users');

By the way, nodeRenderer is entirely for visual customization. For example, if you wanted to render rows without borders, add buttons anywhere, etc.

from react-sortable-tree.

anil1712 avatar anil1712 commented on May 23, 2024

Thanks @fritz-c
convertChildrenKeys is what I was expecting.

But I am facing one more difficulty. How can we sort the children array (title) in ascending order?

from react-sortable-tree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.