473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script for merging cells (across rows) in the same column

I wrote the following script in order to traverse an HTML table and
merge the cells that have the same value across multiple rows. For some
reason, however, it works for the first, third, and fourth columns in
my table, but in the second column, the merged cell is not aligned at
the center vertically. The cells do get merged, but the cells in the
second column are always aligned at the top. Trying cell.valign =
"middle" had no effect.

Any thoughts? Could it be because I'm not actually deleting the cells
that are to be merged with the top of each such block; instead I merely
set style.display to none for these cells.

Here's my script:

var currCell;
var totRows = T1.rows.length;
var totColumns = T1.rows[1].cells.length;
var numValues = T2.rows[0].cells.length-2;

var i,j;
var nextRowMatch = true;

var myCell;

for (i=0; i<(totColumns-numValues); ++i) {

var currRow = 1;
var j=currRow+1;
var numCellsMerge = 1;

var identical = false;

while (j<totRows) {
var currCell = T1.rows[currRow].cells[i].innerText;
var nextCell = T1.rows[j].cells[i].innerText;

if (currCell != nextCell) {

if (i>0) {

var start=(i-1);
var sameValues = 1;

while ((start >=0) && (sameValues == 1)) {
var prevColText =
T1.rows[currRow].cells[start].innerText;
var prevColNextRowT ext =
T1.rows[currRow+1].cells[start].innerText;
if (prevColText != prevColNextRowT ext) {

sameValues = 0;
} else {
start = start-1;
}

}
if (sameValues == 0) {
numCellsMerge = 1;
}

}
if (numCellsMerge 1) {
for (var k=currRow+1; k<j; ++k) {
T1.rows[k].cells[i].style.display = 'none';
}
myCell = T1.rows[currRow].cells[i];
myCell.rowSpan = numCellsMerge;

}

currRow=j;
++j;
numCellsMerge = 1;
identical = false;

} else {
++numCellsMerge ;
++j;
identical = true;
}

}

if (identical) {
if (numCellsMerge 1) {

for (var x=currRow+1; x<totRows; ++x) {
T1.rows[x].cells[i].style.display = 'none';
}
myCell = T1.rows[currRow].cells[i];
myCell.rowSpan = numCellsMerge;

}
}

}

Aug 29 '06 #1
1 4844

samn wrote:
Trying cell.valign = "middle" had no effect.
Using cell.style.vert icalAlign="midd le" did the trick.

Aug 29 '06 #2

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

Similar topics

5
1502
by: David Shorthouse | last post by:
Hello folks, I have an interesting problem and am looking for some advice. I am hoping to build an asp whereby records are pulled from SQL Server. These records will be merely file locations for thumbnail images I hope to display in a grid. Rather than having a grid be constructed row-to-row, I was wondering if it is at all possible to dynamically construct this grid as a table of thumbnails whereby each cell (perhaps 5-6 columns across)...
6
7105
by: David D. | last post by:
I want to be able to access cells within an HTML table, via computed row number and column number. I was considering using oTableID.children and oTR.children arrays. My question is what browsers and browser versions support this? If the children constructs are not fairly universally supported, then what is a better approach to doing this?
5
36881
by: Richard Dixson | last post by:
I created a new C# web application. Basically all I am trying to do is create a table that consists of a few rows with two columns in each. And then to set those columns to text values from my code behind. However I am not able to do this at all, I am going about this wrong, I think and need guideance. If this was just straight HTML I would do this: <table> <tr><td>field 1</td><td>value 1 set by code behind</td></tr>
2
3120
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so that it may help others. If posting this script is against the rules in this group then please accept my appologies. I developped this script so that I can add and remove rows in a table in which I have various input fields and I would use the...
2
16516
by: OceanBreeze | last post by:
Border drawn in C# Table programmatically even if several adjacent horizontal & vertical cells are empty in the table I want to programmatically have border on each and every row and column in the table even if several adjacent horizontal and vertical cells contains no value. The table control (MyTbl) is in ASP. I am programmatically populating the TableCell and TableRow in that MyTbl in ASP. The problem is, no line for the row border gets...
3
2012
by: Eric Layman | last post by:
Hi, I have a script here which will loop thru a table and check for it's background color. But it doesn't work on Firefox. The Error Inspector said "ERROR. obj.cells has no properties How should I work around it to ensure it works for IE and FF?
1
1746
by: mghihor | last post by:
Dear GridView Experts! I have problems with GridView when adding a column using TemplateField. I fill GridView1 from a stored procedure. It has a Select statement and returns 14 columns, AutoGenerateColumns="True". When I add two columns manually to be able to start drag and drop, the drag and drop works OK, but in GridView1_PreRender() and GridView1_RowCreated() I loose values of GridView1.Rows.Cells.Text and e.Row.Cells.Text, these are ""....
1
1778
by: akdemirc | last post by:
Hi, My question is about retrieving single records based on a time column, i mean the result set should not include duplicate rows for a unique time value as an example: A B C D Time ------------------------------------------------------------- x x x x 1 y y y y 1 z z z z ...
1
2516
by: BBMcL | last post by:
Advanced thanks for any helping. I'm running Python on a Mac OS X. Here's the basic situation. A single group of people had various health measurements performed on them over the course of a few decades. But individuals dropped out of the study between examinations. For instance, for the first exam there were 3,000 individuals, then for the second exam (a few years later), there were 2,500, and so on. By the last exam, exam 26, there were...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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 we have to send another system

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.