JavaScript

Thursday, September 16, 2010

Category Tree

Hello Everybody,
There are many occasion when we required hierarchical structure.
In Which we need multilevel structure.E-commerce websites frequently
use this functionality to show various categories of their items.
what we need is to having all child node under its respective parent
such that one can easily differentiate each category-subcategory.
We can achieve this using single table with three fields. i.e
-------------------------------
Id-------Category--------Parent
1            Parent1                  0
2            Child1-Parent1       1
3            subchild-Child1       2
4            Child2-Parent1       1
5            Parent2                 0
6            Child1-Parent2      5
7            subchild1-child1    6
8            subchild2-child1    6
All set..But how to achieve structure as follows:
Parent1
|_Child1-Parent1
|_|_subchild-Child1
|_Child2-Parent1
Parent2
|_Child1-Parent2
|_|_subchild1-child1
|_|_subchild1-child1

Source: ClickHere to see the code.