How to : Computed field
How to : Computed field
VAILLY Olivier
Posts: 19Questions: 0Answers: 0
Hi everybody,
- I've a dataTable mapped on a postgresql table, with 2 columns defined (i.e. Product_qty and Product_price)
- i've an Editor mapped on the dataTable object and it works fine
Now i need to add a third column which will be a computed column with Product_qty * Product_price formula
and when user change (inline) a value in, say, Product_price, the formula is recomputed !
I'm searching for such function and find no solution !
Coould someone help me ?
Thanks
Oliver
This discussion has been closed.
Replies
Hi Oliver,
The
columns.render
option is the way to do this. For example you might use:Allan
Hi Allan, thanks for your response
After your confirmation ( i was near the good result ....) of the code to use,
i retry and i find my mistake !
my syntax to access field in the render method was not good, because of the join of multiple tables in datasource !
for those who have same issue :
render : function (data, type, row) {
return row.my_join_table.my_field * row.same_or_other_table.other_field;
}
now it works fine !
thanks for all :)
Come back !
Now my field is well computed but my problem is a little bit more complicated that i thought ..... :
How to do this ?
Thanks
Pretty sure support for datatables ends after the data displays successfully, But what you need to do is call the cell contents from the DOM and then send it to the database using php or whatever server side language you're using.
Easier said than done.
I don't quite understand why you want to store a value in the database that is computed on the client-side. Surely you could just compute it in the database as well? In fact, if it is a computed value, why store it at all?
Allan
Good point, Why aren't you storing it on the server before sending it to the client?
Never trust the client. Never, ever.
Hi,
I want to store this computed value because it will be used by others applications in other systems !!!!!!!
heuu ... i'm lost at this point :(
to resume :
But i don't see where put the code for computing ...
in php file called by DataTable ?
Store the computed value server side for use by other applications before you even do anything with datatables.
You shouldn't be computing sourced data on the client and then sending it back to the server, that is double handling.
You shouldn't be relying on any response from the users client because it can be spoofed to drop all your tables etc unless you sanitize properly.
Your problem at this point isn't datatables related and this could probably be closed.
Ok Samuel i agree but the script where i should compute the value rely on DataTable no ?
it is called by DataTable and i don't see where place my code because ( and thanks to that) DataTable "machinery" mask all sql stuff !
I'd say don't store it at all - just compute it. You've asked DataTables to compute it - why not just compute it else where as well? I don't understand that point.
However, if you want to store the computed value in the database, I would suggest you use a server-side event to do so. Have a function that computes the value and uses that to store.
Allan