How could i create an dynamically calculated column?
How could i create an dynamically calculated column?
Hello,
As per instructions i have tried to create a working exaple of my issue (i beg your pardon but i'm not a good coder):
http://live.datatables.net/wucojawu/1/edit
Please look at Tiger Nixon: what i wanna do is that as soon as i start to write the salary, in the row to the next column (Salary per Age) appear the salary multiplied for the age.
It should work like this other link:
http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm
In my real case, obviously the dynamically calculated column should work for all the rows and not only one.
Thank you very much for the help
This question has accepted answers - jump to:
Answers
Use
columns.render
. There is detailed documentation on how to use renderers in the manual. Basically you would use the information passed in as the third parameter to the function, perform your calculation and return the value.Note that if you are going to use the data from my example you would need to remove the formatting from the salary column (i.e. remove the commas and $) before you can multiple the value numerically.
Allan
hi Allan, thank you very much for the hint!
I tried to use the columns.render to make the calculation but unfortunately i am not able to make it work. Could you modify the example page to make the columns.render work?
Thank you very much and sorry if i am asking you instead of doing by myself but i am a very weak programmer :(
@Jekko, your header has 7 th elements but your body only has 6 td elements? You mention trying the render function but not able to make it work, can you please update your test bed with what you tried so we can take a look.
As far as the input functionality you want, I would suggest creating an onchange event for it so that you can then update the row using the invalidate function.
Certainly - this would be covered by the support options.
Aide from that, @jr42.gordon's reply is absolutely spot on.
Allan