pass data from the selected row into a standalone editor
pass data from the selected row into a standalone editor
I have an orders table from which I want to use some data (eg OrderID, ItemID) from the selected row as default values in a standalone editor for returning an item.
So in my orders datatable, I have an ‘in table form control’ to create a new row in my returns table
$('#example').on('click', 'a.editor_create', function (e) {
e.preventDefault();
var data = table.row( $(this).parents('tr') ).data();
orderid = data.tblorders.OrderID;
console.log( orderid );
editor.create( {
title: 'Process Refund',
buttons: 'Log Refund and Send Email'
} );
} );
I can retrieve and display, (for example) the ordereid in the console.
How can I get this value into my editor as a default value
var editor = new $.fn.dataTable.Editor( {
ajax: "/ajax/ajax_process_refund.php",
fields: [ {
label: "Order ID:",
name: "tblrefunds.OrderID",
def: orderid
},
.....update
Stumbled across a solution, setting the field value when using the create method
$('#example').on('click', 'a.editor_create', function (e) {
e.preventDefault();
data = table.row( $(this).parents('tr') ).data();
orderid = data.tblorders.OrderID;
editor.create( {
title: 'Process Refund',
buttons: 'Log Refund and Send Email',
} );
editor.field('tblrefunds.OrderID').set(orderid)
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Does your Editor instance already exist (I'm guessing it does)? If so, just use
field().def()to set the default value for that field.Allan