Solved

Tree structure using Jquery / Javascript / Html

Posted on 2013-10-25
8
1,971 Views
Last Modified: 2013-10-29
Hi Experts,

My web application was developed using C#/ASP.NET and for each menu/tab we have a help icon and if we click on help icon it should open a new browser window and should redirect to corresponding contents page (Html files) highlighting left hand side node (contents) and displaying details in the right hand side, similar to this tree structure (http://www.telerik.com/help/aspnet-ajax/introduction-common_changes_backward_compatibility.html).

Foar eg: from application we pass Page name( Page1,Subpage1...etc) like this http://testserver/mauals/index.html?Page1.htm (Assuming user has clicked Help icon on  Page1) and it should Highlight Page1 on the left side of Tree structure and display contents in the right pane.

Can any one help me (with sample code) for the above task  using Jquery/Javascript/Html ?

Thanks in advance
0
Comment
Question by:ksd123
  • 4
  • 3
8 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39602883
There was nothing on Google that fit your needs?

First thing I came across was http://jquery-plugins.net/tag/treeview
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39602888
You can do this on all serverside code (.NET), all client side (jquery/js) or a combo. I do this very thing on some of my internal db sites but I am using classic asp.    If using all serverside, you first need to grab the page name.  You can do this by hardcoding a variable called pageName for instance or what I do is grab the page name from the url.  I don't know how to do that in .net but this may help http://forums.asp.net/t/318949.aspx

Next on your tree code, you have to give the selected page some type of css class that will make it highlight.  

There are also plenty of jquery tree projects.  One is http://www.jstree.com/demo.  If you hard code a javascript variable called pageName, you can then use jquery to mark the appropriate li link with the class jstree-clicked and that will make the branch highlighted.

Using the jstree demo html
  <div id="demo1" class="demo" style="height:100px;">
	<ul>
		<li id="phtml_1">
			<a href="#">Root node 1</a>
			<ul>
				<li id="phtml_2">
					<a href="#">Child node 1</a>
				</li>
				<li id="phtml_3">
					<a href="#">Child node 2</a>
				</li>
			</ul>
		</li>
		<li id="phtml_4">
			<a href="#">Root node 2</a>
		</li>
	</ul>
</div>

Open in new window

You can targe an anchor branch (the 'a' uder the 'li') with jquery like this
  <div id="demo1" class="demo" style="height:100px;">
	<ul>
		<li id="phtml_1">
			<a href="#">Root node 1</a>
			<ul>
				<li id="phtml_2">
					<a href="#">Child node 1</a>
				</li>
				<li id="phtml_3">
					<a href="#">Child node 2</a>
				</li>
			</ul>
		</li>
		<li id="phtml_4">
			<a href="#">Root node 2</a>
		</li>
	</ul>
</div>

Open in new window

I have a working sample I made where I added css to make the targeted a link large.  You can see I hardcoded the page name to match the id of the li.http://jsbin.com/iSEcUBU/1/edit?html,css,js,output
$( document ).ready(function() {
  var pageName="phtml_2";
  $('div#demo1 ul li').each(function(){
    if($(this).attr('id')==pageName){
       $(this).find('a').addClass('jstree-clicked ');
    }
    
  });
});

Open in new window

If you need a little refresher or start with jquery spend a few hours on http://www.codecademy.com/learn
0
 

Author Comment

by:ksd123
ID: 39603695
Thanks padas for your sample code and appreciate your time.

1) I need one more help,in the tree structure left pane shows (Root node 1,child node 1 etc)  and  need  sample code that  shows Details of the Highlighted node  in the Right pane  using Jquery / HTML?

2)I  just want to double check with you that the below JQuery code for highlighting selection of node will be compatable with all browsers (ie7,ie8,ie9,google chrome etc) ?, I heard that  sometime's it may not work (Highlight) in some browsers. Can you suggest me on this ?

$(this).find('a').addClass('jstree-clicked ');
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39603991
I develop on a mac and personally don't support the older browsers in anything I do.  I understand the need for corporate account though.  

The first step is using the jstree demo in ie7,8 and 9.  If that works, then it should be good.   The code $(this).find('a').addClass('jstree-clicked '); is simply adding a class to the anchor so you end up with <a class="stree-clicked" href="#">something</a>.   Jquery 1.x supports the older ie browsers.  Jquery 2.x is lighter weight because they took out the support for older browsers.  So as long as you are using jquery 1.x all should be good.  

I would still suggest making a quick sample page and testing it first.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:ksd123
ID: 39605442
I have created sample page and it's working fine  in all browsers and just need  sample code that  shows Details (static content) of the Highlighted node  in the Right pane  using Jquery / HTML?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39605481
>just need  sample code

http:Q_28277863.html#a39602888

If you take the time to recreate the sample code including html, project css and js, you will see this works.
0
 

Author Comment

by:ksd123
ID: 39608158
Thank you Padas.

I am just asking sample code for the right pane, in the tree structure if I click on "Child node 1" it should display some static content related to "Child node 1"in the right pane  similar to this (http://www.telerik.com/help/aspnet-ajax/introduction-common_changes_backward_compatibility.html).
0
 

Author Closing Comment

by:ksd123
ID: 39608161
Thank you so much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now