Multiply value of column 1 with 6 and than sum it up
Multiply value of column 1 with 6 and than sum it up
 redsunset            
            
                Posts: 44Questions: 15Answers: 0
redsunset            
            
                Posts: 44Questions: 15Answers: 0            
            Hi all!
I know the code to sum it up and I tried to edit it for my purpose. I want to multiply the value of column 1 and column 6 and sum up all results.
I tried it with this code:
         "footerCallback": function ( row, data, start, end, display ) {
                    var api = this.api(), data;
                    // Remove the formatting to get integer data for summation
                    var intVal = function ( i ) {
                       var quantity = data.quantity;
                      var finalproduct = i * quantity;
                        return finalproduct;
                    };
         
                    // Total over all pages
                   var total = api
                        .column( 6 )
                        .data()
                        .reduce( function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0 );
         
                    // Total over this page
                   var pageTotal = api
                        .column( 6, { page: 'current'} )
                        .data()
                        .reduce( function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0 );
                   alert(pageTotal);
        
                    // Update footer
                    $( api.column( 6 ).footer() ).html(
                        '$'+pageTotal +' ( $'+ total +' total)'
                    );
                }
but no success  ... thank you very much for any help in advance!
 ... thank you very much for any help in advance!
This question has an accepted answers - jump to answer
This discussion has been closed.
            
Answers
Hi @redsunset ,
I'm not seeing where you're accessing column 1 in that code, or attempting any multiplication. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
its the line: var finalproduct = i * quantity;
here is a new example: https://jsfiddle.net/prashantpokhriyal/9qLdLnxs/2/
my problem is that I only can get the final sum by creating a third column which holds the product of two other columns.
Is it possible to edit this so I do not need the third column and directly get the the sum of all product results?
thank you in advance!
One option is to use
toArray(). For example:https://jsfiddle.net/7ufhsxLv/
Kevin
fantastic! thank you!