Editor - serverside: Copy a value to another table.
Editor - serverside: Copy a value to another table.
JanNL_FR
Posts: 47Questions: 15Answers: 2
Is it possible to copy the value of an 'id' field in a selected row to another related table (with a button)?
Thanks in advance.
Jan.
This question has an accepted answers - jump to answer
Answers
Sorry its not clear to me what you are asking for. Is the table client side or is it a server side database table?
Are you looking for something like this parent/child editing example?
If you want to send the value of the ID field to the server you can create a [custom button] like this example. You can get the selected row with
row().data()
using theselector-modifier
of{selected:: true}
. See this example. Then use jQuery ajax() to send the value to the server. with thedata
object.If this doesn't then please provide more details of what you are trying to do.
Kevin
Thanks Kevin,
I'll try to explain.
In the datatables_demo table we have Tiger Nixon with id = 1.
Now I want to select the row, press the button that adds the 1 in another table on the server.
If that works, I'd also like to add a session user_id to the same record.
I am already successful in applying the records in a parent/child construction to link them to another table.
Jan
Here are the steps I would employ to send data from the selected row to the server:
-1. Create a Custom button.
-2. Use the following code to get the selected row:
If using the
rowId
option theid
will contain the row's id. Otherwise you will need to get the id from thedata
varaiable.-3. Send the id to the server using using the
data
object of jQujery ajax(). For example:The above code will reside in the custom button function.
Not sure where or what this is but add it to the
data
option of the ajax request.Kevin
After selecting a record, two values are now written to another table.
This works well for a single record.
Would it also be possible to do this with multiple selected records at the same time?
Jan
Yes, with
create()
you can create multiple rows at a time. Pass in the number of rows to create as the first argument tocreate()
, then use the multi-row editing API to set the values for each of the fields per new row.Allan