I have received json response and I want to create html table with data I want to create a table as
Geo Identified Closed Won Qualified Total
NSU 20 0 0 20
US East 50 8 3 61
US West 39 2 16 57
Total 109 10 19 138
My json response is
[{Geo: "US West", SalesStage: "Closed Won", count: 2},
{Geo: "US East", SalesStage: "Closed Won", count: 8},
{Geo: "US West", SalesStage: "Qualified", count: 16},
{Geo: "US East", SalesStage: "Qualified", count: 3},
{Geo: "US East", SalesStage: "Identified", count: 50},
{Geo: "US West", SalesStage: "Identified", count: 39},
{Geo: "NSU", SalesStage: "Identified", count: 20} ]
I have tried as
const summary_data = [{Geo: "US West", SalesStage: "Closed Won", count: 2},
{Geo: "US East", SalesStage: "Closed Won", count: 8},
{Geo: "US West", SalesStage: "Qualified", count: 16},
{Geo: "US East", SalesStage: "Qualified", count: 3},
{Geo: "US East", SalesStage: "Identified", count: 50},
{Geo: "US West", SalesStage: "Identified", count: 39},
{Geo: "NSU", SalesStage: "Identified", count: 20} ];
$.each(summary_data, function (index, item) {
const $tr = $('<tr>');
$tr.append([item.Geo, item.SalesStage, item.count].map(x => $('<td>').text(x)));
$('tbody').append($tr);
});
table {
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 0.5em;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<thead>
</thead>
<tbody>
</tbody>
</table>