I have the following code:
//list is the result of the query of the database
var list =[];
var _this = this, $div = _this.$div, opts = _this.settings, $table = $div.find(opts.tableSelector);
var fieldsToShow = ["Right Identification", "Left Identification", "Total",
"RIGHT IDENTIFICATION RELAPSE", "LEFT IDENTIFICATION RELAPSE", "Total",
"IDENTIFICATION TOTAL IN "];
var i = 0;
$table.html('<table>')
for (var j = 0; j < list.length; j++) {
i = 0;
for (p in list[j]) {
if (p === "Name") {
$table.html('<tr>');
$table.html('<td>' + list[j][p] + '</td><td></td>');
$table.html('</tr>');
} else {
if(p === "GrandTotal" && list[j].Nome === "CountryTown"){
$table.html('<tr>');
$table.html('<td>' + fieldsToShow[i] + 'COUNTRY TOWN</td><td>' + list[j][p] + '</td>');
$table.html('</tr>');
} else {
if(p === "GrandTotal" && list[j].Nome === "Metropolitan"){
$table.html('<tr>');
$table.html('<td>' + fieldsToShow[i] + 'METROPOLITAN</td><td>' + list[j][p] + '</td>');
$table.html('</tr>');
} else {
$table.html('<tr>');
$table.html('<td>' + fieldsToShow[i] + '</td><td>' + list[j][p] + '</td>');
$table.html('</tr>');
i++;
}
}
}
}
}
$table.html('<tr><td>GRAND TOTAL:</td><td>' + (parseInt(list[0].GrandTotal) + parseInt(list[1].GrandTotal)) + '</td></tr>');
$table.html('</table>')
And the following html:
<div class="form-list-result QueryResults hidden">
<div class="form-list-result-header QueryResults hidden">
<label>Query Results</label>
</div>
<table class="table" width="100%">
</table>
</div>
But when I click on the button, the table continues empty, only with <table></table>
When I used the document.write, it used to appear the table, like this:
Contry Town
Right Identification 2
Left Identification 3
Total 5
Right Identification Relapse 1
Left Identification Relapse 1
Total 2
TOTAL IDENTIFICATIN IN COUNTRY TOWN 7
Metropolitan
Right Identification 3
Left Identification 2
Total 5
Right Identification Relapse 1
Left Identification Relapse 1
Total 2
TOTAL IDENTIFICATIN IN METROPOLITAN 7
TOTAL: 14
And the result of the query in database is this:
Name IdDireta IdIndireta SubTotal RIdDireta RIdIndireta RSubTotal GrandTotal
Interior 2 3 5 1 1 2 7
Metropolitana 3 2 5 1 1 2 7