Table Cell Deletion - Problem with Spanning Multiple Columns

A

animesh

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.cells.length - 1;
position = endOfRow - moveFromEnd;
if (position < 0)
{
position = 0;
} // End If

allCellsInRow = allRows.cells;


if(allCellsInRow[position].rowSpan != null &&
allCellsInRow[position].rowSpan > 1)
{
allRows.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.deleteCell(position);
}
else
{
//allRows.deleteCell(position)
if(cellCount < 1)
{
cellCount = 1;
alert("row = " + i + "position=" + position);
allRows.deleteCell(position-1);
}

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

var spanLimit = cellCount;

var startCell = 0;

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

} // End For

} // End If

} // End Function


Help!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top