Connecting Tech Pros Worldwide Help | Site Map

Table Cell Deletion - Problem with Spanning Multiple Columns

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 10th, 2007, 08:05 AM
animesh
Guest
 
Posts: n/a
Default Table Cell Deletion - Problem with Spanning Multiple Columns

I have a simple table structure in which a cell can span multiple
columns

D E F
A D
B C E



So when I click A and say delete column it should delete both the
values "B" & "C". The column span for A is 2.

I wrote the javascript for that, but facing too many issues when
deleting values. Incorrect values are getting deleted. Whenever I
delete I try to count from backwards, --something like this.....

Let me know if theres any standard way to do this.

function DeleteCol() {

var cellCount = 0;
if (isCursorInTableCell())
{

moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
allRows = selectedTable.rows;
var numRows = allRows.length;
for (var i=selectedTR.rowIndex;i < numRows;i++) {

endOfRow = allRows[i].cells.length - 1;
position = endOfRow - moveFromEnd;
if (position < 0)
{
position = 0;
} // End If

allCellsInRow = allRows[i].cells;


if(allCellsInRow[position].rowSpan != null &&
allCellsInRow[position].rowSpan 1)
{
allRows[i].deleteCell(position);
i = i + allCellsInRow[position].rowSpan;
}

else if (allCellsInRow[position].colSpan 1)
{

//allCellsInRow[position].colSpan =
allCellsInRow[position].colSpan - 1;
cellCount = allCellsInRow[position].colSpan;

//Delete that particular column text first
allRows[i].deleteCell(position);
}
else
{
//allRows[i].deleteCell(position)
if(cellCount < 1)
{
cellCount = 1;
alert("row = " + i + "position=" + position);
allRows[i].deleteCell(position-1);
}

if(cellCount == 1)
{
allRows[i].deleteCell(position);
return;
}

var spanLimit = cellCount;

var startCell = 0;

for(;startCell <= spanLimit;startCell++)
{
alert("row=" + i+ " position=" + position);
if(position - 1 0)
allRows[i].deleteCell(position-1);
}
allRows[i].deleteCell(position);
}

} // End For

} // End If

} // End Function


Help!!!

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.