how to find sum of more than one column and display it??

how to find sum of more than one column and display it??

shashidharnkshashidharnk Posts: 7Questions: 2Answers: 0
edited April 2018 in Free community support

Hi,

Am using server side processing to load table, and how do i add more than one columns and display the sum of all the columns in a new row either within the table or in the footer????

can I use rowcallback function?? if so, help me to start with.

thanks n regards,
-SHASHIDHAR

Answers

  • colincolin Posts: 15,146Questions: 1Answers: 2,587

    Hi @shashidharnk ,

    With server side processing, you only have access to the values on the displayed page, so you can only sum what's visible. The footerCallback is called on every draw event, so this would be the best place to do it. Take a look at this example, this should get you going,

    Cheers,

    Colin

  • jgorenejgorene Posts: 1Questions: 0Answers: 0

    Hello @shashidharnk ,

    I workaround that for a while... Finally I found a solution from example as suggested above by @colin and that works well for my needs anyway.
    I just added a line of code below

    var sumCol4Filtered = display.map(el => data[el][4]).reduce((a, b) => intVal(a) + intVal(b), 0 );
    

    We can probably optimize that... here a functional codepen
    If it helps !

This discussion has been closed.