Friday, 15 January 2021

jQuery - Generate HTML Table

 

 Watch this example on YouTube


 

 

@using (Html.BeginForm("Index", "Home"))
{
}

@section Scripts{
    <script type="text/javascript">
        var tbl = $("<table>").attr("id", "tbl1").addClass("table");
        var tr1 = $("<tr>").append($("<th>").append($("<b>").text("Some Text")))
            .append($("<th>").append($("<b>").text("Some other text")))
         .append($("<th>").append($("<b>").text("even more text")));
        var tr2 = $("<tr>").append($("<td>").append($("<b>").text("row 1 column 1")).append($("<span>").attr("id", "someValud")))
            .append($("<td>").append($("<b>").text("row 1 column 2")).append($("<span>").attr("id", "ID2")))
         .append($("<td>").append($("<b>").text("row 1 column 3")).append($("<span>").attr("id", "ID3")));
        tbl.append(tr1);
        tbl.append(tr2);
        $(document.body).append(tbl);
    </script>
}

No comments:

Post a Comment