Addition or sum of column values
Addition or sum of column values
James Payne
Posts: 15Questions: 0Answers: 0
Hello,
is it possible to create the sum of a column's values and display it somewhere near the table?
I'd like to add prices together in a column called bf_ad_rate.
I'm using the PHP and MYSQL version of the server-side setup (which incidentally works like a charm!)
Thanks in advance,
James
is it possible to create the sum of a column's values and display it somewhere near the table?
I'd like to add prices together in a column called bf_ad_rate.
I'm using the PHP and MYSQL version of the server-side setup (which incidentally works like a charm!)
Thanks in advance,
James
This discussion has been closed.
Replies
http://www.datatables.net/examples/advanced_init/footer_callback.html
I have this as my initialization
[code]$(document).ready(function() {
$('#view_booking_forms').dataTable({
"bJQueryUI": true,
'bProcessing':true,
"bServerSide":true,
"bSort":true,
"sPaginationType": "full_numbers",
"sAjaxSource": "includes/view_booking_forms_parse.php",
"oLanguage": {
"sLengthMenu": 'Display 102550100250Allrecords…'
}
});
});[/code]
I have tried pasting the example into the above but I'm not sure what I need to change to make it work for me.
Regards,
James
It would appear to me that you're going to have to add a "fnFooterCallback" function that does the actual summing and updating of the totals in the footer. Take a look at that example's "Initialization Code" section at the bottom of the page and you'll see what I'm referring to. Better still is to look at that page's source to see the HTML too. You'll notice a was added to the table layout in order for this to work.
All I can recommend now is that you go snooping thru the example's source (use your browser's "View page source" capabilities) and don't be afraid to experiment. At least that's what I do and manage to make things work (most of the time).
thanks for your help. I'm pretty much in the same boat at you!
I have pasted the example code in using the fnFooterCallback function on that page and it breaks my code and stopes the table from forming at all.
This is what I mean
[code]$(document).ready(function() {
$('#view_booking_forms').dataTable({
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
/*
* Calculate the total market share for all browsers in this table (ie inc. outside
* the pagination)
*/
var iTotalMarket = 0;
for ( var i=0 ; i
1) Did you define a table layout as shown in that example where a is included?
2) The example code that you pasted makes references to a set of data that has at least 5 columns (aaData[i][4]). Do you have at least 5 columns?
3) I'm not sure if it matters, but, I'd put the function call towards the end of the initialization and not at the top as you have.
Again, these are just WAGs on my part. It's really difficult to diagnose any of this without seeing all of your code and data. Perhaps someone else who know what they're doing can chime in here.
I suggest that you really study that example carefully. It takes a bit of a simpler approach in that the table and data is defined entirely in the HTML so there isn't much to the initialization except the footer callback.
Have sorted it out. I had an empty instead of populating it with columns. I thought the script would add these automatically as it does for the body but I was wrong. I had
[code][/code]
and needed [code]
[/code]
Thanks for all of your help.
James