views:

92

answers:

2

Is there a way to rotate an html table? So, say I had a table like this:

  <table id="table-1" cellspacing="0" cellpadding="2">
        <tr><td>1</td></tr>
        <tr><td>2</td></tr>
        <tr><td>3</td></tr>
        <tr><td>4</td></tr>
        <tr><td>5</td></tr>
        <tr><td>6</td></tr>
    </table>

and wanted to some sort of button that had javascript behind it that could rotate the table any which direction. For example, clicking the right button, results in:

  <table id="table-1" cellspacing="0" cellpadding="2">
        <tr><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td></tr>
    </table>

I have a drag and drop plugin that uses a table, and I am trying to do a piece that allows for a user to add to a queue (that results in the table), and then they can also rotate it around as well. Thanks.

+1  A: 

How about something like this?

    var len = $('#table-1 tr').length;
    var $first = $('#table-1 tr').eq(0);
    for(var i = 1; i < len; i++) {
        $('#table-1 tr').eq(1).find('td').prependTo($first);
        $('#table-1 tr').eq(1).remove();
    }

http://jsfiddle.net/LLknJ/

patrick dw
+2  A: 

There is TableSorter plugin.

serg