I have a jQuery Datatable with 2 rows in the header. I'd like to populate the 2nd row of this header with some total values that I am passing back from the server, in JSON, along with all the data for the content of the table.
I've looked and looked to find a way to do this, but I'm struggling.
Can anyone tell me what the best way to get these values in to the header are please once the data has been obtained from the server?
Here is how I am getting the JSON back from the server and populating the rows of the table:
$.ajax({
url: "<?php echo $this->url($reportResource)?>"
}).done(function(data) {
// populate the data in to the rows of the table
reportTable.rows.add(data.rows).draw();
// the data param here contains an item in the array which contains all
// of the totals I'd like to put in the 2nd header row:
var totalValues = data.totals;
});
Here is the HTML for the table:
<table class="table table-striped" id="report-table">
<br/>
<thead>
<th>Impressions</th>
<th>Sold</th>
<th>Unsold</th>
<th>Percentage</th>
<th>eCPM</th>
<th>Revenue</th>
<th>Commision</th>
<th>Net</th>
</tr>
<tr>
<th style="text-align:right">Totals:</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
And the JSON returned is:
{
"rows": {
"0":{"site":"<website1>","imps":20276,"sold":17308,"unsold":2968,"percentage":85.3620043401,"eCpm":0.0909454034326,"grossRevenue":1.844009,"commission":0.5532027,"netRevenue":1.2908063},
"1":{"site":"<website2>","imps":4485,"sold":3900,"unsold":585,"percentage":86.9565217391,"eCpm":0.0833068004459,"grossRevenue":0.373631,"commission":0.1120893,"netRevenue":0.2615417},
"2":{"site":"<website3>","imps":37,"sold":34,"unsold":3,"percentage":91.8918918919,"eCpm":0.0665405405405,"grossRevenue":0.002462,"commission":0.0007386,"netRevenue":0.0017234},
}
"totals":{"imps":24798,"sold":21242,"unsold":3556,"percentage":85.6601338818,"eCpm":0.0895274618921,"grossRevenue":2.220102,"commission":0.6660306,"netRevenue":1.5540714}
}
Your help is much appreciated.