Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to generate html table vertically? means table start verticaly then goes horizontally
like this
1
1
1
1

second step
1 2
1 2
1 2
1 2

third step
1 2 3
1 2 3
1 2 3
1 2 3

and so on
Posted
Updated 13-Apr-15 19:33pm
v2
Comments
Thanks7872 14-Apr-15 1:17am    
Add four Rows with single <td>,then add <td> to all rows two times. It's possible. What is the question?
Muhamad Faizan Khan 14-Apr-15 1:21am    
sorry the question dynamic generation of html table using js vertically
Kornfeld Eliyahu Peter 14-Apr-15 2:27am    
Sergey Alexandrovich Kryukov 14-Apr-15 2:41am    
The "problem" is way too trivial. You just add some elements to DOM. You can get help only if you show where you stuck.
—SA

XML
<html>
<head>
<title></title>
<style type="text/css">
#myTable
{
border:1px solid;
}
#myTable th
{
background-color:#006699;
color:#ffffff;
}
#myTable th,td {
padding: 5px;
border: 1px solid;
}
</style>
</head>
<body>
<div>
<input id="btnCreate" type="button" name="btnCreate" value="Create Column" />
</div>
<div>
<table id="myTable">
<tr>
<th>
Row 1
</th>
<td>
a
</td>
</tr>
<tr>
<th>
Row 2
</th>
<td>
b
</td>
</tr>
<tr>
<th>
Row 3
</th>
<td>
c
</td>
</tr>

<tr>
<th>
Row 4
</th>
<td>
d
</td>
</tr>
</table>
</div>
<script src="Scripts/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnCreate').click(function () {
CreateColumn();
});
});

function CreateColumn() {
$('#myTable').find('tr td:last-child').each(function (i, el) {
var inputEl = $(el).children().get(0);
$(el).after('<td>' + i + '</td>');
});
}
</script>
</body>
</html>
 
Share this answer
 
Just make table normally after that just convert rows to column using this function

JavaScript
function rowINTOcolumn(tableid){
    $jq("#"+tableid).each(function() {
        var $jqthis = $jq(this);
        var newrows = [];
        $jqthis.find("tr").each(function(){
            var i = 0;
            $jq(this).find("td").each(function(){
                i++;
                if(newrows[i] === undefined) { newrows[i] = $jq("<table><tbody><tr></tr></tbody></table>"); }
                newrows[i].append($jq(this));
            });
        });
        $jqthis.find("tr").remove();
        $jq.each(newrows, function(){
            $jqthis.append(this);
        });
    });
}


pass ID of table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900