Query and update another table for default value for field
Query and update another table for default value for field
Hello
I'm trying to work out how to do this and not having much luck...
So I know I can set the default value of an editor field (https://editor.datatables.net/reference/option/fields.def)
But I need to get that value from another table in the database - and, actually, increment that value in the other table too.
So the table I'm editing is "projects"... it has a "job number" field.
That job number is in another table, "networks" which keeps track of the next job number for the particular network.
How do I get the data from the other table (and update it too!)
Many thanks
Ken
Replies
Hi Ken,
Is the default value static of the life-time of the page? Or is it variable depending on some other conditions on the page?
For the first option you could include the default value you want in the JSON response when the data is initially loaded for the table and use
initComplete
to set the default to that value:Allan
Thanks for this Allan.
My only problem with making the job number static for the lifetime of the page is that if the user doesn't want to add a new project then that job number gets lost - I'd quite like the job numbers to stay in sequence.
I really just need to be able to query the other table at the moment the "new" button is pressed and fill in the job number field with the resultant data. (Yes, I still run the risk of losing a job number out of sequence if they cancel at this stage but it'd be less of an impact than generating a new job number every time the jobs table is loaded).
Thanks as always for your help...
Ken
If the default value is variable, then use the
fields.def
option as a function which will get and return the default value from wherever that information is available.Regards,
Allan
Aaaah. Of course, that's it.
OK, so I've wrapped up the database query/update in PHP and have called that as a basic XMLHttpRequest() in the function there. And that works.
Thanks for your help once again.