Calculate sum of a column without displaying it

Calculate sum of a column without displaying it

islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
edited May 2018 in Free community support

Say I have 4 columns. A, B, C, D.

I want to only make column A, D visible. But column D's values depends on column B and C. And column D's sum in footer, depends on column B and C's sum. So how can I calculate the sum of B and C without actually showing them in the table, just for D to use it?

This question has accepted answers - jump to:

Answers

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

    I just want to point out that the columns are there, but they have a hidden html attribute for them not to be shown.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @islamelshobokshy ,

    Take a look at this example here - it's doing what you want. You can still reference the column even if it isn't visible - the data still exists.

    Hope that helps,

    Cheers,

    Colin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
    edited May 2018

    Woah you're awesome, this is exactly what I needed! Thanks for everything colin :) But knowing that my targets: 3, is dynamic, it isn't a fixed number everytime, is there a way to put an if condition somewhere in there? Or I have to use PHP? (as I try to use little to no PHP inside JS as it's not clean at all)

    Also can I write something like targets: 3,4,9?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi again,

    Yep, you can put an if condition in that footerCallback, for the calculation, that's not a problem! For the columnDefs, you would need to assign it to a variable first, and then refer to that in the table initialisation.

    Cheers,

    Colin

This discussion has been closed.