|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionHave you ever tried to insert an easy-to-use treeview into your homepage or even use a treeview in your web-application? If you have, you will probably know that most ready-made treeviews out there are built in a quite complex manner, making heavy use of client side javascript and difficult-to-handle structures like multi-dimensional arrays and such. There is, however, a more elegant way of implementing a treeview using only one small client-side javascript and making use of DOM (Document Object Model) and basic HTML-tags such as DIV. Easy DHTML TreeviewThe 'Easy DHTML Treeview' builds a treeview on top of the Document Object Model, which
already is hierarchical by definition. The whole idea of the 'Easy DHTML Treeview'
is using simple HTML tags such as
So, when you click on the yellow 'branch name', the javascript function Serialising the treeviewThe good thing about this simple implementation is that it is very easy to construct a treeview from data that can be stored in a database. Whereas other treeview functions and components force you to fill a javascript array (which is only 2 levels deep anyway and therefore not a real n-level tree), 'Easy DHTML Treeview' allows you to simply print the data as if it were a table. The whole functionality of collapsing and unfolding the branches in the tree is then added almost automatically by the single function that does it all! The included demo-project shows you that it is really quite easy to create very dynamic, n-level truly recursive trees using 'Easy DHTML Treeview'. For storing the data in the tree, this data model is used:
Like a treeview, the data model itself is recursive, because topic and topic_1 are the very same table. This means topic has a relation to topic, with the subtopic table in between to implement an n-n relationship. Tips & TricksI got a lot of questions about the treeview so I'd just answer some of them here for your convenience: How can I change the initial state of the treeview from collapsed to expanded? The
answer is quite simple. If you're using the static version (from the live demo-site, simply
omit the style attribute from the How can I liven up the treeview to make it look better? Well, I've been working on a pure-HTML extension of the treeview with a colleague of mine, which draws lines in the treeview, like MFC treeviews do. I will post this version shortly. Cross-browser treeview?I developed this treeview for Internet Explorer 5, which is not such a good idea if you want to develop a cross-browser treeview because Microsoft has the tendency to build all kind of fancy non-standard goodies into it's browser. Luckily some people on the CodeProject have tested it on other browsers and it only seemed to work on IE5 (not even IE4!). I'm now in the process of evaluating what I can do to improve this. Today (June 13th 2001) I checked all my script-entries against the actual standards and found out that all of it should work on browsers supporting CSS Level 1, HTML 4.0 and DOM Level 2. I made some modifications today as well and I'm curious on which browsers the script works correctly. The treeview has been tested on the following browsers:
(Thanks to Jorge Sabater Redondo, Alexandra Berg, Neal Costello, Zinggl Alois, Jens Kreiensiek, Arnt Witteveen, Jamie Nordmeyer, Bryan Pietrzak and Bruce for the testing!) If you have another browser than listed above, please test the script at THIS live-demo site and mail me to tell me if it did or didn't work on your browser... Together we can build a better treeview, I know it! ;-)
| |||||||||||||||||||||||||||||||||||||||||