get sum of all columns at tfooter

get sum of all columns at tfooter

ASHFAQAHMEDASHFAQAHMED Posts: 6Questions: 0Answers: 0
edited February 2012 in General
hello all,

i am trying to get the sum of each column, how should i do that ?

i have used a table on more then 12 pages, and defined at first home page which is included at all pages,
here is code with i want to show the sum of each column

$('#example').dataTable(
{

//"bJQueryUI": true,
"sScrollX": "110%",
"bScrollCollapse": true,
"iDisplayLength": 10,
////// add more show per page list "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]];
"sDom": 'rt<"bottom"iflp<"clear">>',
"sPaginationType": "full_numbers"
} )

Thanks

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    What you can do is something like:

    [code]
    $('#example').dataTable()._('td:nth-child(4)')
    [/code]

    That will give you an array of data from the 4th column which you can sum as you would do any other array :-)

    Allan
  • ASHFAQAHMEDASHFAQAHMED Posts: 6Questions: 0Answers: 0
    Thanks :)
  • ASHFAQAHMEDASHFAQAHMED Posts: 6Questions: 0Answers: 0
    Hello ,

    any example for this ? i have tried but can not have the values for the columns

    Thanks
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Here is my code from above running: http://live.datatables.net/odawav/edit . Have a look at the console in your browser and you'll see the data array.

    Allan
  • davcaddodavcaddo Posts: 3Questions: 0Answers: 0
    Good work Allan, Is there any way i can output the sum result in a div. An example will do, thanks
  • garybrett37garybrett37 Posts: 8Questions: 0Answers: 0
    Hi there, did you manage to resolve this, I am looking to do the same, when I looked at Allans example it doesnt appear to show summary in footer?

    Thanks
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Have you looked at this example: http://datatables.net/release-datatables/examples/advanced_init/footer_callback.html

    Allan
  • garybrett37garybrett37 Posts: 8Questions: 0Answers: 0
    edited June 2012
    Hi Allan, many thanks for the reply, I did indeed see that example and several others but not being good with js I am still struggling. Using your excellent example I did manage to sum a single column but cannot fathom out how to sum multiple from dynamic table. I edited your code to simply sum a column [1] as such;

    [code]

    $(document).ready(function() {
    $('#example').dataTable( {
    "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
    var iTotalCases = 0;
    for ( var i=0 ; i
  • garybrett37garybrett37 Posts: 8Questions: 0Answers: 0
    Does anyone know how much the paid support is?

    Thanks
This discussion has been closed.