![]() |
Web Development »
Client side scripting »
General
Advanced
JScript Tree List Control v3.0By Nathan RidleyCompletely rewritten and much more versatile than my two previous tree list controls, this version includes dynamic branch loading, user-specifiable tree column, and more! |
JavascriptWin2K, WinXP, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

This is my third attempt at making a TreeListControl for Internet Explorer-based web applications. The first was very slow and required ASP to generate a tree. The second has lots of features, and even resizable columns, but, while it did not suffer from the freeze-up delays that occurred in the first one, was generally sluggish in operation if there were more than a few nodes on the screen. This latest version has tighter code and is generally more versatile all round. It doesn't have resizable columns, but it shouldn't be too hard to put them in. If I do that, I'll upload the updated version here. The only other major limitation of this control is that it is fixed-width. That is, you have to specify the exact width of each column, and this determines the control width.
Features that version 3.0 has are:
To use the control, simply include treelistcontrol.js and treelistcontrol.css in your html file, then, inside the element (body tag, div tag, or where ever) you want to render the tree inside, place a script tag and build the tree according to the API. A demo of how to do this is inside the included zip file.
See the API below for explanations of the tree's objects, and the file demo.htm for an example of how to use the tree.
TreeListControl(strRootNodeLabel, strRootNodeIconSrc, boolHideColumnHeadings, boolHideRootNode)
strRootNodeLabel: the label to use for the root node
strRootNodeIconSrc: the path to the node's icon
boolHideColumnHeadings: don't show the column headings
boolHideRootNode: don't show the root node showColumnHeadings: hide/show the column headings. The visibility of the column headings will automatically change depending on the state of this property.
showRootNode: hide/show the root node. The visibility of the root node will automatically change depending on the state of this property.
all: this is a collection (array) contain references to all the nodes that were assigned a non-null refKey when added to the tree. usage: mytree.all['mynoderefKey']
allNodes: this is a collection containing references to every node in the tree, indexed by the node's automatically assigned ID property.
rootNode: a reference to the tree's root node. This is of type TreeListControlNode.
iconPath: the path to the location where the tree's images are stored. The default is 'tlcimages/'. TreeListControlColumn (intWidth, strTitle, boolPreventRowClickEvents)
intWidth: the width, in pixels, of the column.
strTitle: the heading/title of the column. Use a zero-length string if no title is desired.
boolPreventRowClickEvents: when a row is clicked, it fires the onclick event for that row. Setting this parameter to true will prevent clicks in this row from firing that event. TreeListControlNode (boolShowChildren, strIconSrc, strXMLSrc, strReferenceKey)
boolShowChildren: this specifies the initial expand/collapse state for the node.
strIconSrc: the path to the icon image to use.
strXMLSrc: if the children of this node are to be loaded at run-time when the node is expanded, this parameter should contain the URL of the XML file. Set to null or '' if not used.
strReferenceKey: if you want to use your own identifiers for each node, instead of the automatically-assigned ID that each node has, specify the identifier here. It can be an integer or a string, and, once the node has been added to the tree, you can access the node via the all property of the TreeListControl object. onclick: the javascript to execute when the onclick event fires for that node. Only set this before the node has been added to the tree. expand: shows the node's children.
collapse: hides the node's children.
setText( strColumn1, strColumn2, ..., strColumnN ): sets the node's text in each column.
setColumnText( intColumn, strText ): sets the text for the node in the specified column.
add( oNodeObject ): appends a node object to this node's children. DO NOT use this method if this node has not yet been added to the tree.
insertBefore( oNodeObject ): inserts the supplied node immediately before this node.
insertAfter( oNodeObject ): inserts the supplied node directly after this node.
remove(): removes this node from the tree completely and returns a reference to the node so that it can be reinserted elsewhere if desired.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Dec 2002 Editor: Chris Maunder |
Copyright 2002 by Nathan Ridley Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |