Created
April 13, 2012 13:48
-
-
Save pgaertig/2376975 to your computer and use it in GitHub Desktop.
Transpose HTML table using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var t = $('#thetable tbody').eq(0); | |
var r = t.find('tr'); | |
var cols= r.length; | |
var rows= r.eq(0).find('td').length; | |
var cell, next, tem, i = 0; | |
var tb= $('<tbody></tbody>'); | |
while(i<rows){ | |
cell= 0; | |
tem= $('<tr></tr>'); | |
while(cell<cols){ | |
next= r.eq(cell++).find('td').eq(0); | |
tem.append(next); | |
} | |
tb.append(tem); | |
++i; | |
} | |
$('#thetable').append(tb); | |
$('#thetable').show(); | |
} |
This code works
It works great. But I have other requirement. I have multiple tables on my pages and these tables are dynamicaly generated. And all of these tables have headers. I want to transponse the table including the headers. And want to maintain the row styles too. I would be great if you modify the js to meet the above requirement. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you modify this script so that it runs when a button is clicked?