473,508 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help!! HTML rowspan does not work with a tree table?

I am trying to create a tree table (javascript code was adopted from
online source) but the rowspan in td tag does not work well when I
toggle the rows. Here is the sample code, notice the row "4" should be
in the Type 1 section (click on the arrow and expand it, it will
display correctly), but when it is collapsed, it is pushed downwards to
Type 2 section. Could not figure out what is the reason. Any ideas?
Thanks!

<html>
<head>
<style type="text/css">
..tier1 { margin-left: 0; }
..tier2 { margin-left: 1.5em; }
..folder { background:
url(http://cool.zoto.com/img/16x16x1/a85...213d9a606-.jpg)
no-repeat; float: left; height: 14px; width: 16px; padding-right: 3px
}
table {
width: 100%;
empty-cells: show;
border-collapse: collapse;
}
td {
border: 1px solid #d0d0d0;
padding: 1px;
vertical-align: top;
}
</style>
</script>

<script language="javascript1.2">
function toggleRows(elm) {
var rows = document.getElementsByTagName("TR");
elm.style.backgroundImage =
"url(http://cool.zoto.com/img/16x16x1/a85cc1b26a569459cdcb29d213d9a606-.jpg)";
var newDisplay = "none";
var thisID = elm.parentNode.parentNode.parentNode.id + "-";
// Are we expanding or contracting? If the first child is hidden, we
expand
for (var i = 0; i < rows.length; i++) {
var r = rows[i];
if (matchStart(r.id, thisID, true)) {
if (r.style.display == "none") {
if (document.all) newDisplay = "block"; //IE4+ specific code
else newDisplay = "table-row"; //Netscape and Mozilla
elm.style.backgroundImage =
"url(http://cool.zoto.com/img/16x16x1/65b6fbbbcda367eaea940bd14b5c1a85-.jpg)";
}
break;
}
}

// When expanding, only expand one level. Collapse all desendants.
var matchDirectChildrenOnly = (newDisplay != "none");

for (var j = 0; j < rows.length; j++) {
var s = rows[j];
if (matchStart(s.id, thisID, matchDirectChildrenOnly)) {
s.style.display = newDisplay;
var cell = s.getElementsByTagName("TD")[0];
var tier = cell.getElementsByTagName("DIV")[0];
var folder = tier.getElementsByTagName("A")[0];
if (folder.getAttribute("onclick") != null) {
folder.style.backgroundImage =
"url(http://cool.zoto.com/img/16x16x1/65b6fbbbcda367eaea940bd14b5c1a85-.jpg)";
}
}
}

}

function matchStart(target, pattern, matchDirectChildrenOnly) {
var pos = target.indexOf(pattern);
if (pos != 0) return false;
if (!matchDirectChildrenOnly) return true;
if (target.slice(pos + pattern.length, target.length).indexOf("-") >=
0) return false;
return true;
}

function collapseAllRows() {
var rows = document.getElementsByTagName("TR");
for (var j = 0; j < rows.length; j++) {
var r = rows[j];
if (r.id.indexOf("-") >= 0) {
r.style.display = "none";
//alert(r.id);
}
}
}
</script>

<title>SSTree Tree Table</title>

</head>

<body onload="collapseAllRows();">
<table border=1 width=100% cellspacing=0 ><tr><td class="header"
align='left'>Title</td></tr>
</table>
<table border=1 width=100% cellspacing=0 cellpadding=2px>
<tr>
<td align='left'>A</td>
<td align='left'>B</td>
<td align='left'>C</td>
<td align='left'>D</td>
<td align='left'>E</td>
</tr>

<tr id="1" class="a">
<td align='left'rowspan='5'>TYPE1</td>
<td><div class="tier1"><a onclick="toggleRows(this)"
class="folder"></a>1</div></td>
<td>ABCDE</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr id="1-1" class="a">
<td><div class="tier2"><a class="doc"></a>2</div></td>
<td>ABCDE</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr id="1-2" class="a">
<td><div class="tier2"><a class="doc"></a>3</div></td>
<td>ABCDE</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr id="2" class="a">
<td ><div class="tier1"><a onclick="toggleRows(this)"
class="folder"></a>4</div></td>
<td>ABCDE</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr id="2-1" class="a">
<td><div class="tier2"><a class="doc"></a>5</div></td>
<td>ABCDE</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>


<tr id="3" class="a">
<td align='left'rowspan='3'>TYPE2</td>
<td ><div class="tier1"><a onclick="toggleRows(this)"
class="folder"></a>6</div></td>
<td>ABCDE</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr id="3-1" class="a">
<td><div class="tier2"><a class="doc"></a>7</div></td>
<td>ABCDE</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr id="3-2" class="a">
<td><div class="tier2"><a class="doc"></a>8</div></td>
<td>&nbsp;</td>
<td>ABCDE</td>
<td>ABCDE</td>
</tr>

</body>
</html>

Sep 26 '06 #1
1 3839
smilecry wrote:
I am trying to create a tree table (javascript code was adopted from
online source) but the rowspan in td tag does not work well when I
toggle the rows. Here is the sample code, notice the row "4" should be
in the Type 1 section (click on the arrow and expand it, it will
display correctly), but when it is collapsed, it is pushed downwards to
Type 2 section. Could not figure out what is the reason. Any ideas?
This is actually an HTML (or maybe CSS) problem and nothing to do with
JavaScript. When you "hide" an element using display:none, it is
completely removed from the document flow, as if it wasn't there:

"Please note that a display of 'none' does not create an invisible
box; it creates no box at all."
<URL: http://www.w3.org/TR/CSS21/visuren.html#x17 >

Therefore when you "hide" some rows, your rowspan encompasses rows that
previously weren't within its scope because the intervening rows are no
longer in the flow.
[...]
<script language="javascript1.2">
The language attribute is deprecated, type is required. In particular,
*never* use that particular value for a language attribute unless you
are certain of the ramifications and know that they are required.

[...]
<tr id="1" class="a">
The value of an ID attribute can't start with a digit (it can contain
digits though).
--
Rob

Sep 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1177
by: ATS | last post by:
PRB: Can not get UserControl/HTML/OBJECT to work on XP/SP2/IIS/IE6 Please help, I can not get my UserControl to work from a simple OBJECT tag in a simple HTML web page on Windows XP with SP2...
4
5092
by: Joe | last post by:
Hello, I have created a login page using dotnet. I am using requiredFieldValidator and noticed that the code works fine in IE but not in Netscape, Opera, Mozilla, Firefox, etc. For example...
12
2234
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation...
4
5764
by: Andrzej Jaworek | last post by:
Hello, I have a "tree" table: Id - primary key ParrentId - (foreign key) related to Id Title ..... when I delete some record I want to delete it with all childs (cascade
3
1643
by: Rolf Welskes | last post by:
Hello, this is a hint only. If you make a custom control for example witch generates code <div......</div> and I put such a control in a page then in html-view of the aspx-file I could...
12
3849
by: vietgurlqt | last post by:
I don't what is wrong my site but some of my members cant view it on firefox. I been browsing the net for answer but i havent find the solution. Some said add <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
4
16956
by: prasath03 | last post by:
Dear All, Can anybody help me about my coding, i'm inserting the image file to database using jsp. When i execute the code, the following error is occurred: java.sql.SQLException: Insert...
0
1447
by: Academia | last post by:
The Help Class example requires only a simple copy, paste into a form and run. Which I did. For it to relate to what I am trying to find out I set the "Help Navigator) combobox to "Topic" I...
1
1972
by: khadar siddi | last post by:
I have tested this in the following two browsers. 1.Internet Exolorer 2.Mozilla FireFox In Internet Explorer: ------------------------ When I right click and see the view source...the html...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.