SP2 breaks IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • foldface@yahoo.co.uk

    #1

    SP2 breaks IE

    Hi
    Sorry but to view the code below you'll have to copy it into a temp.html file,
    haven't access to a online web page anymore.
    The code switches the rows and columns of a table. Its been tried in the
    versions below. Note that it works in the latest version of IE before SP2,
    whats changed?
    By not working I mean that it'll switch the columns/rows twice then lose
    some of the information? Can fix it by substituting the commented out lines
    for the ones above.

    mozilla 1.7.2, works
    firefox 0.9.3, works
    IE6.0.2800, works
    IE6.0.2900, doesn't work

    Any ideas
    Ta
    F


    <style>
    ..theTableClass
    {
    border: groove;
    }
    </style>

    <table id=theTable class=theTableC lass>
    <tr id=realOne>
    <td class=Bob sue>Some random text </td>
    <td class=Sue>Some random text </td>
    <td class=Sue>Some random text </td>
    </tr>
    </table>

    <input type=button value=pressme onclick=SwapCol umnsAndRows('th eTable')>

    <script>



    function SwapColumnsAndR ows(tableId)
    {
    var theTable = document.getEle mentById(tableI d)
    if(theTable == null) return;

    var theTable2 = document.create Element("table" );

    var numRows = theTable.rows.l ength;
    var numCells = theTable.rows[0].cells.length;

    for(var i=0; i<numCells; i++)
    {
    var newRow = theTable2.inser tRow(-1)
    for(var j=0; j<numRows; j++)
    {
    var cell = theTable.rows[j].cells[i];
    //var newCell = theTable2.rows[i].insertCell(-1);
    var newCell = newRow.insertCe ll(-1);
    SwapCells(cell, newCell);
    }
    }

    while (theTable.rows. length > 0)
    {
    theTable.delete Row(0);
    }

    var numRows = theTable2.rows. length;
    var numCells = theTable2.rows[0].cells.length;

    for(var i=0; i<numRows; i++)
    {
    var newRow = theTable.insert Row(-1)
    for(var j=0; j<numCells; j++)
    {
    var cell = theTable2.rows[i].cells[j];
    //var newCell = theTable.rows[i].insertCell(-1);
    var newCell = newRow.insertCe ll(-1);
    SwapCells(cell, newCell);
    }
    }

    while (theTable2.rows .length > 0)
    {
    theTable2.delet eRow(0);
    }
    }

    function SwapCells (cell1, cell2)
    {
    var dummyCell;
    if (document.creat eElement && (dummyCell = document.create Element('td')))
    {
    cell1.parentNod e.replaceChild( dummyCell, cell1);
    cell2.parentNod e.replaceChild( cell1, cell2);
    dummyCell.paren tNode.replaceCh ild(cell2, dummyCell);
    }
    }
    </script>
  • Grant Wagner

    #2
    Re: SP2 breaks IE

    foldface@yahoo. co.uk wrote:
    [color=blue]
    > Hi
    > Sorry but to view the code below you'll have to copy it into a temp.html file,
    > haven't access to a online web page anymore.
    > The code switches the rows and columns of a table. Its been tried in the
    > versions below. Note that it works in the latest version of IE before SP2,
    > whats changed?
    > By not working I mean that it'll switch the columns/rows twice then lose
    > some of the information? Can fix it by substituting the commented out lines
    > for the ones above.
    >
    > mozilla 1.7.2, works
    > firefox 0.9.3, works
    > IE6.0.2800, works
    > IE6.0.2900, doesn't work[/color]

    Here is a little simpler version that works in all the browsers listed above:

    <style type="text/css">
    ..theTableClass {
    border: groove;
    }
    </style>
    <table id=theTable class=theTableC lass>
    <tr id=realOne>
    <td class=Bob sue>Some random text </td>
    <td class=Sue>Some random text </td>
    <td class=Sue>Some random text </td>
    </tr>
    </table>
    <input type=button value=pressme onclick=SwapCol umnsAndRows('th eTable')>
    <script type="text/javascript">
    function SwapColumnsAndR ows(tableId) {

    var theTable = document.getEle mentById(tableI d)
    if (!theTable) {
    return;
    }

    var theTable2 = theTable.cloneN ode(false);

    var numRows = theTable.rows.l ength;
    var numCells = theTable.rows[0].cells.length;

    for(var i = 0; i < numCells; i++) {
    var newRow = theTable2.inser tRow(-1);
    for(var j = 0; j < numRows; j++) {
    newRow.appendCh ild(theTable.ro ws[j].cells[i].cloneNode(true ));
    }
    }

    while (theTable.first Child) {
    theTable.remove Child(theTable. firstChild);
    }

    for (var i = 0; i < theTable2.child Nodes.length; i++) {
    if (theTable2.chil dNodes[i].nodeName == 'TBODY') {
    theTable.append Child(theTable2 .childNodes[i]);
    break;
    }
    }
    }
    </script>

    - I do a shallow clone [cloneNode(false )] of the original table (initially I had a
    solution that involved theTable.parent Node.replaceChi ld(theTable2, theTable); but it
    did not work in Opera 7.54 - you could probably get away with
    document.create Element('table' ); now)
    - I create a new row for each existing row, then do a deep clone [cloneNode(true)]
    of each cell and append it to the new row
    - I then remove all children from the original table (note all _children_, not all
    rows, doing it this way removes the TBODY)
    - I then go through the new table, locate the TBODY and append it to original table
    (I suppose I should cloneNode() it, but I don't see the need) - it is necessary to
    go looking for the TBODY and not just assume it's firstChild because of the
    differences between IE and Gecko-based browsers

    Using my code should be much faster than swapping each cell into a new table and
    swapping them back. Tested and working in:

    IE 6.0.2800 and 6.0.2900
    Firefox 0.9.3
    Mozilla 1.7.2
    Opera 7.54

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    Working...