Search code examples
twitter-bootstrapbootstrap-modalbootstrap-table

Bootstrap Modal passing data through on('click-row.bs.table'


I have to Bootstrap Modal Windows... One with a table(#items) and another(#item) with form Data.

Now i want to click on a row in the table and want to open the other modal windows and want to pass data through.

$('#items-table').on('click-row.bs.table', function (e, row, $element) {
    $('#items').modal('hide');
    $('#item').modal('show');
    //Need to pass row.id to #item
});

this is where i catch the click from the table row. Here i get the row.id which i want to use in my #item form.

$('#item').on('shown.bs.modal', function (event) {
  var button = $(event.relatedTarget); // Button that triggered the modal
  var itemId = button.data('item-id') ;// Extract info from data-* attributes

})

these two lines which are standing there are from a button which has a data- Attribute. This is working fine, but how i can pass the row.id from the table?


Solution

  • So i figured out to managed this properly:

        $('#items-table').on('click-row.bs.table', function (e, row, $element) {
        $('#items').modal('hide');
        $modal('#item');
        $modal.data('id', row.id);
        $modal.modal('show');
        //Need to pass row.id to #item
    });
    

    and catch it in the modal like:

    $('#item').on('shown.bs.modal', function (event) {
    
      var modal = $(this);
      var id = modal.data('id');
    
    })
    

    big thanks to @wenyi for that link!