Created
October 25, 2016 09:06
-
-
Save Origame/da6adb549c7757cf8c25b76ffbbff673 to your computer and use it in GitHub Desktop.
Transpose rows & columns in HTML table (for mobile purposes mainly)
This file contains hidden or 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
$("table").each(function() { | |
if ( !$(this).hasClass("reverted") ) { | |
var $this = $(this); | |
var newrows = []; | |
$this.find("tr").each(function(){ | |
var i = 0; | |
$(this).find("td, th").each(function(){ | |
i++; | |
if(newrows[i] === undefined) { | |
newrows[i] = $("<tr></tr>"); | |
} | |
newrows[i].append($(this)); | |
}); | |
}); | |
$this.find("tr").remove(); | |
$.each(newrows, function(){ | |
$this.append(this); | |
$this.addClass('reverted'); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment