Dynamic data field
Dynamic data field
Hi there. I'd like to have a field in the editor which would allow me to edit another field. I have the data option set to null, and use the render to calculate VAT by combining two other fields. Now I'd like to be able to edit this field, to calculate the original price by subtracting VAT.
I was thinking of something towards creating a custom editor.inline() field, but my javascript knowledge is limited. I've tried the editor events open and preOpen, but they are never called as I'm getting the following error:
Unable to automatically determine field from source. Please specify the field name
Would this be possible? Thanks in advance.
This question has an accepted answers - jump to answer
Answers
This is going to be a little bit tricky I think, since Editor isn't designed to edit data that doesn't really exist. There are two options I can think of:
1) Preformat the data (either client or server-side - it doesn't matter) before DataTables is given the data to display. The Preformat would basically just add the calculated value into the data set (in Editor's PHP or .NET libraries you could use a formatter for this).
2) Set the
columns.data
option to be something invalid for the calculated column (rather thannull
- perhapsdata:'notHere'
) and use that same value for thefields.name
option in Editor. That will link the two. But I think you'll need to useval()
to set the value oninitEdit
since Editor wouldn't be able to see the value as it doesn't exist!Allan
Thanks a lot Allan! I got it working