Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3613326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:06:34+00:00 2026-05-18T22:06:34+00:00

I have some data like this : (AT sql sERVER) MemberID,ParemtID,Amt,OtherInfo 1, NULL, 200,dfdsf

  • 0

I have some data like this :
(AT sql sERVER)

MemberID,ParemtID,Amt,OtherInfo
1,       NULL,    200,dfdsf
2,       1,       300,DFDF
3,       1,       400,DFS
4,       3,       75,NULL

Now I want build Tree like this :
alt text
Only using JS.
Above data can be passed in JSON / XML / CSV / Formatted Text
How can i generate such dynamic tree in JS only ?
Please don’t suggest PHP / .NET solutions.
I would prefer a JQuery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:06:35+00:00Added an answer on May 18, 2026 at 10:06 pm

    And, here you go:

    http://jsfiddle.net/vVmcC/
    http://jsfiddle.net/vVmcC/4/

    You’ll want to style it up yourself, obviously. But this should get you started:

    var members = [
        {memberId : 1, parentId:null, amount:200, otherInfo:"blah"},
        {memberId : 2, parentId:1, amount:300, otherInfo:"blah1"},
        {memberId : 3, parentId:1, amount:400, otherInfo:"blah2"},
        {memberId : 4, parentId:3, amount:500, otherInfo:"blah3"},
        {memberId : 6, parentId:1, amount:600, otherInfo:"blah4"},
        {memberId : 9, parentId:4, amount:700, otherInfo:"blah5"},
        {memberId : 12, parentId:2, amount:800, otherInfo:"blah6"},
        {memberId : 5, parentId:2, amount:900, otherInfo:"blah7"},
        {memberId : 13, parentId:2, amount:0, otherInfo:"blah8"},
        {memberId : 14, parentId:2, amount:800, otherInfo:"blah9"},
        {memberId : 55, parentId:2, amount:250, otherInfo:"blah10"},
        {memberId : 56, parentId:3, amount:10, otherInfo:"blah11"},
        {memberId : 57, parentId:3, amount:990, otherInfo:"blah12"},
        {memberId : 58, parentId:3, amount:400, otherInfo:"blah13"},
        {memberId : 59, parentId:6, amount:123, otherInfo:"blah14"},
        {memberId : 54, parentId:6, amount:321, otherInfo:"blah15"},
        {memberId : 53, parentId:56, amount:10000, otherInfo:"blah7"},
        {memberId : 52, parentId:2, amount:47, otherInfo:"blah17"},
        {memberId : 51, parentId:6, amount:534, otherInfo:"blah18"},
        {memberId : 50, parentId:9, amount:55943, otherInfo:"blah19"},
        {memberId : 22, parentId:9, amount:2, otherInfo:"blah27"},
        {memberId : 33, parentId:12, amount:-10, otherInfo:"blah677"}
    
    ];
    var testImgSrc = "http://0.gravatar.com/avatar/06005cd2700c136d09e71838645d36ff?s=69&d=wavatar";
    (function heya( parentId ){
        // This is slow and iterates over each object everytime.
        // Removing each item from the array before re-iterating 
        // may be faster for large datasets.
        for(var i = 0; i < members.length; i++){
            var member = members[i];
            if(member.parentId === parentId){
                var parent = parentId ? $("#containerFor" + parentId) : $("#mainContainer"),
                    memberId = member.memberId,
                        metaInfo = "<img src='"+testImgSrc+"'/>" + member.otherInfo + " ($" + member.amount + ")";
                parent.append("<div class='container' id='containerFor" + memberId + "'><div class='member'>" + memberId + "<div class='metaInfo'>" + metaInfo + "</div></div></div>");
                heya(memberId);
            } 
        }
     }( null ));
    
    // makes it pretty:
    // recursivley resizes all children to fit within the parent.
    var pretty = function(){
        var self = $(this),
            children = self.children(".container"),
            // subtract 4% for margin/padding/borders.
            width = (100/children.length) - 2;
        children
            .css("width", width + "%")
            .each(pretty);
    
    };
    $("#mainContainer").each(pretty);
    

    It is by no means an optimal solution. The first loop will become a nightmare for performance the more data you begin loading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.