I am working on creating table rows dynamically on button click. So I have some map data returned from server in this format for two different services:
reportData:
Site Recovery Vaults:[14503.13, 1019, 971.97, 1140.69, 1129.17, 1217.46, 1182.04, 1244.61, 1262.06, 1237.42, 1373.54, 1335.12, 1390.05, 0]
Total:[14503.13, 1019, 971.97, 1140.69, 1129.17, 1217.46, 1182.04, 1244.61, 1262.06, 1237.42, 1373.54, 1335.12, 1390.05, 0]
reportData:
Disks:[13045.35, 985.73, 966.29, 987.02, 959.48, 1012.96, 1010.27, 1018.69, 1013.26, 1015.25, 1075.85, 1090.98, 1110.98, 798.57]
Images:[7.3, 0.56, 0.56, 0.57, 0.55, 0.57, 0.56, 0.57, 0.57, 0.57, 0.6, 0.6, 0.59, 0.43]
Snapshots:[81.52, 15.75, 11.09, 1.7, 1.65, 7.84, 7.68, 0.26, 1.45, 9.9, 4.55, 7.36, 7.15, 5.14]
Total:[31948.73, 2233.36, 2097.09, 2241.42, 2135.11, 2489.97, 2548.01, 2500.82, 2502.82, 2618.89, 2861.08, 2809.17, 2860.55, 2050.44]
Virtual Machine[18814.57, 1231.32, 1119.14, 1252.13, 1173.43, 1468.61, 1529.5, 1481.3, 1487.53, 1593.17, 1780.08, 1710.24, 1741.83, 1246.31]
So, my main objective is to display Total row at the bottom of the table body.
As you can see, for service 1 – Total row data is already at bottom but for service 2 it is present at some other index.
function to create table row and table head dynamically:
function getReportData(){
var client_id = $("#clientid").val();
var report_id = $("#reportid").val();
var name = $("#reportid option:selected").text();
$.ajax({
url: "/emerge/mvc/ajax/cloudhealth/ReportCostData",
data: {
report_id: report_id,
client_id: client_id
},
type: "POST",
success: function (response) {
var td = "", tableBody="", thead="";
if(Object.keys(response.reportData).length != 0){
thead = "<tr><th scope='col'>Service Category</th>";
for(var i = 0; i < response.timeDimension.length; i++){
td = td+"<th scope='col'>"+response.timeDimension[i]+"</th>";
}
thead = thead+td;
var nColumns = Math.max.call(null, ...Object.values(response.reportData).map(v => v.length));
Object.entries(response.reportData).forEach( ([rowId, values]) => {
values = values.length < nColumns ? values.concat(...[...Array(nColumns - values.length)].map(_ => '0')) : values;
tableBody = tableBody + `<tr><td>${rowId}</td><td>${values.join(`</td><td>`)}</td></tr>`;
});
document.getElementById('thead').innerHTML = thead;
}else{
tableBody = "<tr><td colspan='"+response.timeDimension.length+1+"' style='text-align: center;padding-top: 100px;font-size: 1.23em;'>No Data Available</td></tr>";
}
document.getElementById('report_data').innerHTML = tableBody;
document.getElementById('rpt_namediv').innerHTML = "<h6>"+response.cloudHealthReport.report+" : "+name+"</h6>";
document.getElementById('reportdataDiv').style.display = "block";
},
error: function (error) {
console.log(`Error ${error}`);
}
});
}
I want to display this Total row value at the bottom of the table body whatever the data returned by the server for different services.
