pass data from the selected row into a standalone editor

pass data from the selected row into a standalone editor

crush123crush123 Posts: 417Questions: 126Answers: 18
edited September 2016 in 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

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    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

This discussion has been closed.