Passing table values to custom editor form

Passing table values to custom editor form

_Ronnie__Ronnie_ Posts: 19Questions: 5Answers: 0

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

  • _Ronnie__Ronnie_ Posts: 19Questions: 5Answers: 0

    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.

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Answer ✓

    You can use the ajax.data option to modify the data sent to the server when DataTables requests data (which you can trigger using ajax.reload()).

    This blog post uses that technique to show a child table based on a selected row in a parent table.

    Allan

  • _Ronnie__Ronnie_ Posts: 19Questions: 5Answers: 0

    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

This discussion has been closed.