Custom Button to Edit a Modal Form

Custom Button to Edit a Modal Form

johnwjohnw Posts: 13Questions: 5Answers: 0

I'm new to DataTables, but I have a custom button that I am using to edit the data in the Modal form. Currently, I like to use the modal form, instead of the standard edit form that comes with the editor. So in the DataTable, I have several rows of data. When I select a row and click on the custom (Edit) button, I want to pass all of the data to the modal form. What is the best way. Thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Using row().data() will get the data for a row and let you use it to populate whatever form you want. For example you could use table.row( { selected: true } ).data().

    Allan

  • johnwjohnw Posts: 13Questions: 5Answers: 0

    Allan,

    I was able to get the selected value, but how would I pass that data to the modal('show'). Thanks.

    extend: "selectedSingle",
    text: "Edit",
    action: function ( e, dt, button, config ) {
    //console.log( dt.row( { selected: true } ).data() );
    var selected = dt.row( { selected: true } ).data();
    $('#myModal').modal('show');

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    It really depends upon what you have in the modal. Bootstrap doesn't really define what can be put into the modal content, other than simply "html". So you would put whatever you want in there as you would with any other jQuery / DOM method - use $().html() for example.

    Allan

  • johnwjohnw Posts: 13Questions: 5Answers: 0

    Alllan,

    I'm new to datatables, but I got it to work. Thanks!

This discussion has been closed.