Click here to Skip to main content
Licence 
First Posted 16 Mar 2005
Views 137,821
Downloads 5,479
Bookmarked 41 times

Tree View

By Bryon Baker | 16 Mar 2005
Tree View builds tree browsers for your web pages.
1 vote, 5.0%
1

2
3 votes, 15.0%
3
6 votes, 30.0%
4
10 votes, 50.0%
5
4.18/5 - 20 votes
1 removed
μ 4.11, σa 1.87 [?]

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.
    <script language="javascript" src="scripts/tree_view.js"></script>
  2. Hook into the event that calls a method when the page is loaded:
    <body onLoad="CreateProjectExplorer()">
  3. Create a function that builds the tree:
    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:

// 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

About the Author

Bryon Baker

Web Developer

Australia Australia

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThanx Pinmemberajay_nahan22:36 25 Jan '09  
QuestionHow to use it in asp.net2.0 PinmemberVimalSaifudin20:39 11 Nov '07  
QuestionOpening the URL in the same window Pinmemberai4u4:00 28 Jun '07  
Questionhow to display xml data in treecheckbox using javascript Pinmembersnitu19:35 8 Apr '07  
GeneralNot running Pinmembersdhiman1:06 28 Dec '06  
GeneralDrawing the tree in a special location Pinmemberislam galileo4:13 19 Apr '06  
GeneralRe: Drawing the tree in a special location Pinmemberislam galileo4:16 19 Apr '06  
GeneralRe: Drawing the tree in a special location Pinmemberjrios9:24 21 May '06  
I insert a table and to rootCell variable assign :
rootCell=tblMenu.cells(0);
Note:
"tblMenu" is the name of the table,
 
I hope you understand me, bye Poke tongue | ;-P
GeneralRemoving Plus When there are no child nodes PinmemberMikan2313:39 14 Feb '06  
GeneralRe: Removing Plus When there are no child nodes Pinmembermrtsherman17:45 30 Apr '06  
GeneralRe: Removing Plus When there are no child nodes PinmemberMikan2320:51 30 Apr '06  
GeneralRe: Removing Plus When there are no child nodes Pinmembermrtsherman6:37 2 May '06  
GeneralRe: Removing Plus When there are no child nodes PinmemberMikan2314:13 18 May '06  
Generalthanks PinmemberMerlin Rose22:13 5 May '09  
GeneralThank You Pinmemberdavidgev10:46 30 Nov '05  
GeneralTreeView Vertical Lines PinmemberLorraine Concos6:41 30 Sep '05  
GeneralRe: TreeView Vertical Lines PinmemberBryon Baker17:23 30 Sep '05  
GeneralExpand Tree View PinmemberLorraine Concos5:28 28 Sep '05  
GeneralRe: Expand Tree View PinmemberBryon Baker11:25 28 Sep '05  
Generalline provision PinmemberSudhakar J2:17 27 Sep '05  
GeneralRe: line provision PinmemberSudhakar J2:32 27 Sep '05  
Generalexpand tree node Pinmembermwong702517:14 8 Aug '05  
GeneralRe: expand tree node PinmemberBryon Baker0:46 9 Aug '05  
GeneralThanks PinmemberEEmadzadeh16:59 6 Aug '05  
GeneralRe: Thanks PinmemberSudhakar J5:54 27 Sep '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 16 Mar 2005
Article Copyright 2005 by Bryon Baker
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid