Addition or sum of column values

Addition or sum of column values

James PayneJames Payne Posts: 15Questions: 0Answers: 0
edited December 2010 in General
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

Replies

  • James PayneJames Payne Posts: 15Questions: 0Answers: 0
    Anyone?
  • MikeSMikeS Posts: 113Questions: 1Answers: 0
    Does this not give you a hint?

    http://www.datatables.net/examples/advanced_init/footer_callback.html
  • James PayneJames Payne Posts: 15Questions: 0Answers: 0
    It does Mike and looks just what I'm looking for, but I have no idea how to implement it into my code.

    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
  • MikeSMikeS Posts: 113Questions: 1Answers: 0
    Well I'm not sure that I'm the one to try to explain this stuff to you :) I'm a noob at this and I what I do is just look thru the example code and stumble across solutions.

    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).
  • James PayneJames Payne Posts: 15Questions: 0Answers: 0
    Hi Mike,

    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
  • MikeSMikeS Posts: 113Questions: 1Answers: 0
    I'm going to be taking wild guesses here since I can't see your HTML for the table layout.

    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.
  • James PayneJames Payne Posts: 15Questions: 0Answers: 0
    edited December 2010
    Hi Mike,

    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
  • davcaddodavcaddo Posts: 3Questions: 0Answers: 0
    how do i get the sum total in real figure, not in percentage
This discussion has been closed.