I have a dataTable with 200+ records in which each row there's button to delete that record, when the button is pressed a modal from Bootstrap pops up.
The problem is when I change "page" with the pagination option from dataTable the information inside the modal is not being updated with the corresponding ID. When I click in any row from the 1st page it works ok, but when I change page is when the information gets stucked with the last id I pressed from the first page.
Any ideas?
Mi code looks like this:
<table class="table table-bordered table-hover tablewithtooltip" id="dataTable">
<thead>
...
</thead>
<tbody>
<tr>
<td>
<a href="#myModal" role="button" class="btn delete-smt-btn" data-toggle="modal" id="111">Delete Row</a>
</td>
<td>Some info</td>
</tr>
<tr>
<td>
<a href="#myModal" role="button" class="btn delete-smt-btn" data-toggle="modal" id="112">Delete Row</a>
</td>
<td>Some info</td>
</tr>
...
</tbody>
</table>
This is my jQuery:
$('body').on('hidden', '#myModal', function () {
$(this).removeData('modal');
});
var table = $('#dataTable').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"aaSorting": [[ 3, "asc" ]],
"oLanguage": {
"sLengthMenu": "Mostrar _MENU_ registros por página"
}
});
$('.delete-smt-btn').on('click', function(e){
id = e.currentTarget.id;
url = "mypage.com/something?p_something=" + id;
$('#myModal').modal({
remote : url
});
$('#myModal').removeData();
});
// I have some tooltips on my table, and I was having kind of the same issue when
// I changed pages with dataTable, the tooltip wasnt showing and I solved it with
// this but I cant make it work with modal.
table.$('[rel="tooltip"], [data-toggle=tooltip]').tooltip({
html: true
}).click(function(e) {e.preventDefault();});