Adding addition data - foreign key id - to 'create' request

Adding addition data - foreign key id - to 'create' request

awaegelawaegel Posts: 2Questions: 1Answers: 0

Hello,

I have a nested datatables scenario when I need to use the editor on the inner, or child data. I have update and and remove functionality working find. When I make a new record, though, I need the id of the parent record to send to the server so it can create a foreign key reference.

Is there a way I can interrupt or override the 'create' function with my own code so I can query my data object to obtain the parent id? Unable to find an example for this scenario.

Thanks!

Answers

  • awaegelawaegel Posts: 2Questions: 1Answers: 0

    Solved my own problem, though probably not as elegantly as possible.
    1. Set a global javascript variable 'parent id'
    2. I'm using 'row details' to show/hide the child datatable, so whenever I open a row I grab its ID and set parent_id to that:

    $('#mytable tbody').on('click', 'td.details-control', function () {
        if ( row.child.isShown() ) {
            // close it
        } else {
            // open it and init child datatable
            parent_id = row.data().id
        }
    })
    
    1. Use the preSubmit event to set editor value:
    editor.on( 'preSubmit', function ( e, d, type ) {
        if (type === 'create') {
            d.data[0].parent_id = parent_id;
        }
    });
    
This discussion has been closed.