Passing table values to custom editor form
Passing table values to custom editor form
I have a custom form for data entry. I would like to include a DataTable in the custom form, loaded from AJAX. However, I also want to pass an ID to the load script that relates to the row being edited. To clarify:
DT_RowID Name name_id
1 Fred 2
2 John 9
3 Dave 7
When editing the first row, I want to pass name_id 2, so the custom form loads a DataTable using:
ajax: {
url: 'modal_table.php?name_id={name_id}',
type: 'POST'
},
...where it substitutes {name_id} for '2'.
And, of course, editing row 2, it will pass name_id for that row.
Can this be achieved?
Kind regards
Ronnie
This question has an accepted answers - jump to answer
Answers
Replying to my own thread!
Will it work to use the on open event to initialise the datatable? I can then pull the value from the passed data array.
You can use the
ajax.data
option to modify the data sent to the server when DataTables requests data (which you can trigger usingajax.reload()
).This blog post uses that technique to show a child table based on a selected row in a parent table.
Allan
Thanks - should have thought to look at parent/child tables! The issue I was having was being unable to get row data via the 'open' event listener for editor.
I got around this by using table.row( editor.ids(true) ).data();
Ronnie