Solved

Tree structure using Jquery / Javascript / Html

Posted on 2013-10-25
8
2,031 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

730 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