Custom Button to launch Modal

Custom Button to launch Modal

pmabeypmabey Posts: 7Questions: 3Answers: 0

Before I show the various pieces of code I have tried I wanted to see if its possible to use a custom button to launch a modal? Currently I have my own button in the HTML page that launches a modal using the following JS:

    $("#myModal").on("show.bs.modal", function(e) {
            var rowData = table.row( { selected: true } ).data();
            var link = $(e.relatedTarget);
            $(this).find(".modal-body").load(link.attr("href"));
    });

This works well, fires up a modal that then loads a remote page, which just so happens to also contain a datatable in it.

What I wanted to do was add a custom button for aesthetic purposes that did the same thing. I have the following that opens a separate window:

    new $.fn.dataTable.Buttons( table, [
            { extend: "selectedSingle",
              text: "Circuits",
              action: function ( e, dt, node, config ){
                    var rowData = dt.row( { selected: true } ).data();
                    window.open( 'fiber_util.html?fiber_id='+rowData.fiber_id );
              }
            }
    ] );

But rather that open a separate window, I would prefer to use a modal.
I'm sure its not as simple as copying the show.bs.modal stuff into the button action as I've tried that so was wondering if what I was trying to do was even possible, or if anyone has had success with this?

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
  • bindridbindrid Posts: 730Questions: 0Answers: 119

    I am working on a full blown one at work where the user clicks on a button, that brings up a list of users in a datatable in a modal dialog. The pick a name, that that is used to populate the form below the modal

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

    What you need to do is call the Bootstrap API methods to show the model. You would use the call in the action method rather than window.open - the Bootstrap documentation details their API.

    This is exactly the method that Editor uses for its Bootstrap integration :).

    Allan

This discussion has been closed.