Pushing calculated data to database on change
Pushing calculated data to database on change
I have the following code running:
{ data: null,
"render": function(data, type, row){
var invoice_amt = (data.vendor_billing['billable_hours'] * data.vendor_billing['rate']);
return invoice_amt;
}
}
Billable hours and the rate calculates the invoice amount field automatically and displays it correctly.
I would like to push the calculated value to the database to be stored anytime it changes. I have tried naming the data field vendor_billing.hours_invoiced amount but that breaks the calculation and with null it does not update the database.
How would I go about doing this?
Replies
How are you currently submitting information to the server? Are you using Editor and its PHP or .NET libraries, or something else?
Thanks,
Allan
I am using Editor and it's the PHP library. I also have inline editing on the fields.
The
columns.render
function is client-side only, so what I would suggest here is that you use a server-side event to calculate the value when creating or editing an entry and have that use$editor->field(...)->setValue(...);
.What I don't get though is why you want to store a number you are just going to calculate anyway?
Allan
Thanks, Allan. My thought is to store the calculated value in the database so if the rate ever changes the previously stored sums will not change. They have to always stay as they have originally been calculated and paid.