Click here to Skip to main content
15,881,559 members
Articles / Web Development / HTML
Article

Tree View

Rate me:
Please Sign up or sign in to vote.
4.22/5 (22 votes)
16 Mar 20051 min read 184.9K   7.2K   43   30
Tree View builds tree browsers for your web pages.

Sample Image - screenshot.gif

Introduction

Tree View builds tree browsers for your web pages. It was inspired by D. D. de Kerf who created Easy DHTML treeview.

However, it was not practical for creating complex dynamic trees. So I took his ideas and wrote a JavaScript that uses DOM to build the hierarchical document he created with static HTML.

To build the tree is very straightforward:

  1. You include the treeview.js file into your HTML.
    HTML
    <script language="javascript" src="scripts/tree_view.js"></script>
  2. Hook into the event that calls a method when the page is loaded:
    HTML
    <body onLoad="CreateProjectExplorer()">
  3. Create a function that builds the tree:
    JavaScript
    function CreateProjectExplorer()
    {
        Initialise();
        // This MUST be the called before
        // any other of treeview's funcitons.
    
        // Build a test project.
        d = CreateTreeItem( rootCell, "img/project.gif", 
            "img/project.gif", "Point of Sale terminal", 
            null, null );
        d2 = CreateTreeItem( d, "img/folder_closed.gif", 
             "img/folder_open.gif", "Actors", null, null );
        // .....
    }

That's it! You are up and running with a tree browser.

The function signature is:

JavaScript
// Creates a new package under a parent. 
// Parameters:
//    parent: The parent element of the new element. (E.g. a folder)
//    img1FileName: File name of the "unclicked" image. (E.g. Closed folder)
//    img2FileName: File name of the "clicked" image. (E.g. Open folder)
//    nodeName: The text to display for the tree node.
//    url: The url to link to when the node is clicked.
//    target: Target when the node is clicked.
//            Possible values are: Frame name, _blank, _self
// Returns:
//    The newly created tree node item. 
//    To create children of the new node pass the returned 
//    node in as a parent of another new node.
function CreateTreeItem( parent, img1FileName, 
                         img2FileName, nodeName, url, target )

Thanks to D. D. de Kerf for the inspiration!

Note: This script is supplied "as is" without any form of warranty. Rewritten Software shall not be liable for any loss or damage to person or property as a result of using this script. Use this script at your own risk!

You are licensed to use this script free of charge for commercial or non-commercial use providing you do not remove the copyright notice or disclaimer from the comment section in the script.

Have fun!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Thanks Pin
EEmadzadeh28-Sep-05 16:23
EEmadzadeh28-Sep-05 16:23 
GeneralDynamic Treeview Pin
EEmadzadeh1-Aug-05 16:40
EEmadzadeh1-Aug-05 16:40 
Generalnot so bad Pin
pradeep shree27-Mar-05 1:15
pradeep shree27-Mar-05 1:15 
GeneralNice, but.. Pin
tommy skaue22-Mar-05 21:30
tommy skaue22-Mar-05 21:30 
GeneralRe: Nice, but.. Pin
Bryon Baker23-Mar-05 1:46
Bryon Baker23-Mar-05 1:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.