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

  • SEARCH
  • Home
  • 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 8836191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:26:11+00:00 2026-06-14T09:26:11+00:00

I have a requirement to show the root node in jsTree when using the

  • 0

I have a requirement to show the root node in jsTree when using the php/mysql implementation. All the relevant code is below along with screen shots of the output.

Current table structure: (sorry can’t embed images yet…)
https://i.stack.imgur.com/pig1V.jpg

Current output:
https://i.stack.imgur.com/N4F8G.jpg

As you can see the actual root node called ROOT is not shown in the tree. The various snippets of code that displays the above is:

javascript:

.jstree({
    // List of active plugins
    "plugins" : [ 
        "themes","json_data","ui","crrm","dnd","search","types","hotkeys","contextmenu" 
    ],

    // I usually configure the plugin that handles the data first
    // This example uses JSON as it is most common
    "json_data" : { 
        // This tree is ajax enabled - as this is most common, and maybe a bit more complex
        // All the options are almost the same as jQuery's AJAX (read the docs)
        "ajax" : {
            // the URL to fetch the data
            "url" : "_demo/server2.php",
            // the `data` function is executed in the instance's scope
            // the parameter is the node being loaded 
            // (may be -1, 0, or undefined when loading the root nodes)
            "data" : function (n) { 
                // the result is fed to the AJAX request `data` option
                return {

                    "operation" : "get_children", 
                    "id" : n.attr ? n.attr("id").replace("node_","") : 1

                }; 
            }
        }
    },

PHP:

function get_children($data) {
    $tmp = $this->_get_children((int)$data["id"]);
    if((int)$data["id"] === 1 && count($tmp) === 0) {
        ## - No data returned
    }
    $result = array();
    if((int)$data["id"] === 0) return json_encode($result);
    foreach($tmp as $k => $v) {
        $result[] = array(
            "just_id" => $k,
            "attr" => array("id" => "node_".$k, "rel" => $v[$this->fields["type"]]),
            "data" => $v[$this->fields["title"]],
            "owner" => $v[$this->fields["owner"]],
            "state" => ((int)$v[$this->fields["right"]] - (int)$v[$this->fields["left"]] > 1) ? "closed" : ""
        );
    }
    return json_encode($result);
}

function _get_children($id, $recursive = false) {
    $hbhbhbh = fSession::get('nodes_allowed[nodes]');
    if (in_array($id, $hbhbhbh)) {

        $children = array();
        if($recursive) {
            $node = $this->_get_node($id);
            $this->db->query("SELECT `".implode("` , `", $this->fields)."` FROM `".$this->table."` WHERE `".$this->fields["left"]."` >= ".(int) $node[$this->fields["left"]]." AND `".$this->fields["right"]."` <= ".(int) $node[$this->fields["right"]]." ORDER BY `".$this->fields["left"]."` ASC");
        }
        else {
            $this->db->query("SELECT `".implode("` , `", $this->fields)."` FROM `".$this->table."` WHERE `".$this->fields["parent_id"]."` = ".(int) $id." AND FIND_IN_SET(".$this->fields["owner"].", '".implode(',', fSession::get('nodes_allowed[nodes_visible]'))."') ORDER BY `".$this->fields["position"]."` ASC");
        }
        while($this->db->nextr()) $children[$this->db->f($this->fields["id"])] = $this->db->get_row("assoc");
        return $children;
    } else {
        $children = array();
        return $children;
    }
}

As you can see from the javascript, I am initially requesting node 1 to load. but it only shows the node directly below it. If I initially load another node further down the tree (effectively making that node the root node), it loads all the sub nodes under it, but doesn’t show the initial node.

If someone could point me in the right direction, I would really appreciate it.

Thanks
Alan

  • 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-06-14T09:26:12+00:00Added an answer on June 14, 2026 at 9:26 am

    For anyone else having the same issue..

    I eventually just added the root node details to the front of the json string returned by the PHP script when the tree is loaded. It then just shows the root node, and loads the leafs via ajax when the user expands it. Simpler than I thought….

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

Sidebar

Related Questions

I'm using the Superfish jQuery menu system and have a requirement to show all
We have a business requirement to show a cost summary for all our projects
I have a requirement to show an EditText at 45 degree angled to horizontal
I have a requirement that I need to show my records in a gridview
I have a requirement where after the login, i need to show a tabbar
While developing my WordPress application i have a requirement where i need to show
To fullfill a requirement I have to show a tooltip manually for 30 seconds.
I have a requirement to show a custom modal jQuery confirmation when a user
I have a requirement, wherein i need to show a wait message while an
I have a requirement to load a UIWebView wrapped inside a UINavigationController, and show

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.