How to create tables from column data instead of row data in HTML? -
according article @ w3 schools, 1 can create basic table in html this:
<table border="1"> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table>
from above, appears 1 enters data rows.
i have situation need enter of data columns. possible?
<table border="1"> <tc> <td>row 1, cell 1</td> <td>row 2, cell 1</td> </tc> <tc> <td>row 1, cell 2</td> <td>row 2, cell 2</td> </tc> </table>
you're best bet render table rows, , use javascript invert table
the following code invert table (this sample code uses jquery)
$("table").each(function() { var $this = $(this); var newrows = []; $this.find("tr").each(function(){ var = 0; $(this).find("td").each(function(){ i++; if(newrows[i] === undefined) { newrows[i] = $(""); } newrows[i].append($(this)); }); }); $this.find("tr").remove(); $.each(newrows, function(){ $this.append(this); }); });
update:
here version works th elements well: http://jsfiddle.net/zwdlj/
Comments
Post a Comment