Calculate sum of a column without displaying it
Calculate sum of a column without displaying it
islamelshobokshy
Posts: 99Questions: 20Answers: 1
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:
This discussion has been closed.
Answers
I just want to point out that the columns are there, but they have a hidden html attribute for them not to be shown.
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
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
?Hi again,
Yep, you can put an if condition in that
footerCallback
, for the calculation, that's not a problem! For thecolumnDefs
, you would need to assign it to a variable first, and then refer to that in the table initialisation.Cheers,
Colin