Script For Merging Cells (across Rows) In The Same Column

Aug 29, 2006

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 prevColNextRowText =
T1.rows[currRow+1].cells[start].innerText;
if (prevColText != prevColNextRowText) {

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;

}
}

}

View 1 Replies


ADVERTISEMENT

JQuery :: Merging The Table Cells?

Feb 2, 2010

I am trying to manipulate table cells in a dynamically created table but I find it next to impossible how to do it.

The table I have has the following structrure:

--------------
| Color | Item |
|------|------|
|Blue...| Car |
|------|------|
|Blue...| Boat |
---------------

what i want to do is using javascript or jquery on the client side to convert this table to the following structure:

--------------
| Color | Item |
|------|------|
|........| Car |
|Blue...|------|
|........| Boat |
---------------

I can get up to the point to increase colspan of row1, cell 1 to 2 but this creates the following structure:

--------------
| Color | Item |
|------|------|
|.........| Car. |
|Blue |------|-------|
|........| Blue. | Boat. |
----------------------|

how to delete the extra table cell.

View 5 Replies View Related

Table - Create A Row Dynamically With 3 Cells(i.e Column)

Jul 27, 2009

I am able to create a row dynamically with 3 cells(i.e column). In my 3rd cell i need to add another row. Is it possible to acheive it. I am using Java script for it. This is the table structure:

[Code]...

View 9 Replies View Related

Cells Hide/show In Each Of The Rows Of A Table?

Aug 16, 2010

I have a query regarding the hide/show of the cells in a table.The first column is 'Yes and No' options using combo box, 2nd option is 'input field', 3rd column is also 'Yes and No' option using combo box, and 4th option is also 'input field'.What I want is to make a table using JAVASCRIPT, in which if i select 'No' from the first row first column, i want to hide the remaining 3 cells of the first row. Otherwise if i select 'yes' from the first row first column i want to show all the 3 other options of the first row. Also in between if I select 'No' from the first row third column i want to hide the first row fourth column cell. Selecting 'yes' from the first row third column will show the first row fourth column.I want apply the same setting of hide and show cells into the remaining columns also.

By selecting 'no' from first column -> hide other corresponding cells of the row by selecting 'yes' from the first column -> show other corresponding cells of the row

AND ALSO

By selecting 'no' from third column -> hide fourth cell of the corresponding/same row by selecting 'yes' from the third column -> show fourth cell of the corresponding/same row

I have posted this question in the tablular form, but it is now showing in the proper format. Anyone in the forum please help me to make this table using JAVASCRIPT. I need this table within a day or two.

View 3 Replies View Related

JQuery :: Selecting Rows Which Have A First Column That Is Not Empty?

Jun 7, 2010

At the moment I am trying to select rows (TRs) which have a first column (TD) that is not empty. (has some text in it)I have tried the following:

$(#myTable).find("tbody").find("tr:has(td:first-child:not(:empty))")

Now I am only getting one row as a result. (the first which fullfills the reqs) Am I doing something wrong? Or is there a better way of doing that.

View 3 Replies View Related

Merging Two Functions?

Jan 18, 2007

Is it possible to merge two functions like these?

<script type="text/javascript">
function showdiv(pass) {
setTimeout('showdiv2("'+pass+'")', 750);
}
function showdiv2(pass) {
var divs = document.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){
if (document.getElementById)
divs[i].style.visibility="visible";
}
else {
if (document.getElementById)
divs[i].style.visibility="hidden";
}}}
</script>

View 10 Replies View Related

Merging 2 CSS Files

Feb 16, 2011

the best way to merge two css files?

View 5 Replies View Related

JQuery :: Converting 1 Column Table To Two Column

Aug 10, 2010

I'm using drupal, and am having trouble to convert a table to a one field two column at code level.Is it possible to manipulate it using jquery using odd and even?

View 2 Replies View Related

Merging 2 Onclick Events

Jun 29, 2009

I attached an onclick event to a link, however I have another one, that needs to be put on the same link, unfortunately I have no idea how to do it. how can I attach the function changecolor to the "abcdefgh" link?

View 1 Replies View Related

Concept Behind Merging Two Arrays Together?

Jul 17, 2011

not sure I understand the concept behind merging two arrays together. I know that I have to make a deep copy of each array before applying the function. I know that I have to create a temp value to store the information in the arrays while I insert, but not sure how to keep in numeric order. array 1 = [3, 7, 12, 15, 22, 45, 56] and array 2 = [1, 2, 5, 17, 20] What simple code could I start with to create this.

View 7 Replies View Related

JQuery :: Merging Two Plugins To Work Together?

Apr 5, 2011

I'm starting to use jQuery lately. I'm trying to combine jquery.selectbox-0.5_style_3 with another script to google maps v3. If I don't use styling selectbox, I don't have any problem with selecting some option from selectbox and centering map on coords which are values of this selectbox. But since im using styled selectbox (changes <option> to <li>). I have no idea how to trigger google maps script to work when i change value on styled selectbox. I have actual value from styled select, but don't know what to do next..

View 2 Replies View Related

Make A Column As A Checkbox Column?

Sep 12, 2009

Can i make a column as a checkbox column?

View 1 Replies View Related

JQuery :: Manipulating Gridview And Merging Two Code Snipets?

Oct 14, 2010

I need some help in jQuery code I am working on. I have an asp.net grid view that I can’t manipulate in the server so I need to do it on client side. The gridview has a file name in the first column. All the files I deal with are in a known single folder on the server

I set a blank column at the end of each row and I want to:

1. Take the file name from the first TD (appears as simple text) and change the file extension (from doc to flv)

2. Check if the file exist in the server

3. If exist, put it in the last (blank) TD after changing the file extension (from doc to flv)

4. If exist Wrap it with <A href=”filename.flv”>filename.flv</a> and make it clickable for the user to download

Here is where I need the help: First problem: I manage taking the file name from the first TD and put it in the last one (see code below) but the text appears as regular text and the link is not active

The Gridview ID is "SearchResultsGV"
1. jQuery(function() {
2. jQuery(".SearchResultsGV > tbody > tr:not(:has(table, th))")
3. .css("cursor", "pointer")
4. .click(function(e) {

[Code]...

View 3 Replies View Related

Adding Table Rows - Putting In A Dropdown Box That Contains Numbers That Will Dynamically Show The Rows

May 1, 2009

i'm creating a ASP page, which is going to have a form in it that needs filling out. part of the form will be a table with a header row, then the next rows will have text boxes that need filling out. is there a way of putting in a dropdown box that contatins numbers that will dynamically show the rows. for example if i select 5, then five rows of text boxes will appear. if i select 14 then 14 appear.

View 3 Replies View Related

JQuery :: Data Table Creates Rows Dynamically - Buttons In Those Rows Do Not Fire The Onclick Event?

May 3, 2010

I have some JQuery that makes an Ajax call and then adds some rows to an existing table.

function
LoadDestinationTable() {
$("#destinationTable tr:gt(0)"[code]...

The problem is that the only place where the click event fires is on the rows that were added when the page was 1st rendered – the th, for example.I also tried adding an onclick event handler to the input button’s creation – that also does not fire.

View 1 Replies View Related

Simple Grid Rows - Columns - When Select Input Type - Line Should Change Color Than Other Rows

Feb 8, 2010

I realize this script and I do not know where to begin:

1) A simple grid rows / columns.

2) The first column contain an input type = "checkbox"

3) When select the input type, the line should change color than the other rows, and you should open a popup window.

For points 1, 2 you are OK. Point 3 is the difficulty.

View 24 Replies View Related

Delete Rows That Has No Activity & No $ In JavaScript(Yellow Colored Rows)?

May 13, 2010

I have a HTML table with 800 rows. How can I delete rows that has no Activity & no $ in JavaScript(Red Colored Rows)? Please note I can have 1 or more than 1 assessments with 1 or more than 1 activity. Sample data.

NameAddressAssessmentActivity$
BelaTorontoFirst AssessmentActivity 110
AsifTorontoFirst Assessment

[code]....

View 1 Replies View Related

Swapping Table Cells

Jul 23, 2005

How in javascript can I swap the cells in a table? I know I can copy the innerHTML and style and other bits manually but can I just swap 2 cells in different rows?

View 1 Replies View Related

Put Images In Table Cells?

Jan 7, 2010

I am confuseif i use JS.. its should be in <head> but table should be in <body>.. how am i going to use that.. and put images in that table cell using JS?

View 6 Replies View Related

Randomize / Swap Td Cells?

Aug 8, 2010

I've been banging my head for two days now trying to figure out how i can swap td cells. There are a lot of examples of how to order rows, but i can seem to find any on how to swap td cells. Has anyone a good referal for this.

View 4 Replies View Related

Adding Row/cells To A Table?

Nov 24, 2010

In my attempt to understand the workings of the code at: [URL].. I modified it a bit. My question is: What am i doing wrong with the 'testContents()' function? The rows of the table see to be added to the display, but I can not confirm that fact with the test function.

Code:
<html>
<head>
<title>New Table Rows</title>
<script type="text/javascript">
// From: http://www.webdeveloper.com/forum/showthread.php?t=238921

[Code]...

View 2 Replies View Related

Highlighting Table Cells With JS - Firefox Vs. IE

Jul 23, 2005

I have written a simple webpage that presents a table. A JS function
allows the viewer to click on a cell and each cell with the same
content has the background color changed to lime green. Each cell that
was previously highlighted has the background color changed back to
white. This works great with Firefox but does not work correctly with
IE. In IE, none of the previously highlighted cells has the background
color changed back to white. How can I modify the syntax so that it
will work in both browsers? Below is the JS function...

View 14 Replies View Related

JQuery :: How To Retrieve The Selected Cells

Jan 4, 2010

I am new to jQuery and I would like to process a matrix operationusing PHP.The front-end code is done bellow, its a 3x3 table. the user couldselect/deselect individual cells of the table and click the buttonthat calls a PHP script that will run some function. How do I know if a cell is selected? Is there is is_selectedfunction in jQuery? Would it be possible to send a 3x3 array to my PHP script?Please provide me with any info on thisMTMy current test code.

<html><head><title>Test</title>
<script type='text/javascript'
src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'></

[code]....

View 4 Replies View Related

JQuery :: Resizing Cells In The Table?

Oct 13, 2008

I have table like this:

<table>
<tr>
<td><div class="drop">a</div></td>
<td><div class="drop">a</div></td>

[Code].....

but if I once resize the block called res, it always select block called drop and I'd like to split the cells only if I just resizing the block called res.

View 3 Replies View Related

JQuery :: Use This To Insert New Cells In A Table Row?

May 15, 2010

I know that JQuery is a very powerful library and was just wondering if it had the following capability that I really need.

Lets say I need to insert new cells into a table row, I know how to do this basic task, but I need to insert my cells in a highly unusual way due to some of the requirements that are needed for the new cells.

I need to be able to insert cells a certain distance into the row, For example, if a row was 1000pixels wide, is there a feature in JQuery that would allow me to insert the cell 250pixels into the row and have a cell width of 50pixels and insert another cell 500pixels into the row with a cell width of 100pixels. I know how to set a cells width using JQuery, just not distance into a row.

The values wont ever be the exact same as above though because they are actually read from a database, so for example, one cell would have the following values [code]...

View 1 Replies View Related

Regarding The Hide/show Of The Cells In A Table?

Aug 16, 2010

I have a query regarding the hide/show of the cells in a table.

The first column is 'Yes and No' options using combo box, 2nd option is 'input field', 3rd column is also 'Yes and No' option using combo box, and 4th option is also 'input field'.

What I want is to make a table using JAVASCRIPT, in which if i select 'No' from the first row first column, i want to hide the remaining 3 cells of the first row. Otherwise if i select 'yes' from the first row first column i want to show all the 3 other options of the first row. Also in between if I select 'No' from the first row third column i want to hide the first row fourth column cell. Selecting 'yes' from the first row third column will show the first row fourth column.

I want apply the same setting of hide and show cells into the remaining columns also.

By selecting 'no' from first column -> hide other corresponding cells of the row
by selecting 'yes' from the first column -> show other corresponding cells of the row

AND ALSO

By selecting 'no' from third column -> hide fourth cell of the corresponding/same row by selecting 'yes' from the third column -> show fourth cell of the corresponding/same row

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved