I have a modal popup that closes when I select an item in a table.
The popup closes, but doing so leaves my template html
blocked.
Why is this happening?
This is the code I use to close the popup:
$(document).ready(iniciar);
function iniciar() {
$("#busqueda_parroquia tr td").click(clickTabla);
}
$(document).ready(function () {
var table = $('#busqueda_parroquia').DataTable();
var dato = "";
//para seleccionar una opcion
$('#example tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
dato = "";
console.log(dato);
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
dato = $(this).find("td:eq(0)").text();
console.log(dato);
}
});
});
$("#BusquedaParroquia").on('click', 'tr', function (e) {
e.preventDefault();
var renglon = $(this);
var campo1, campo2, campo3;
$(this).children("td").each(function (i) {
switch (i) {
case 0:
campo1 = $(this).text();
break;
case 1:
campo2 = $(this).text();
break;
case 2:
campo3 = $(this).text();
break;
}
})
$("#txt_codigo").val(campo1);
$("#txt_nombre").val(campo2);
if (campo3 == "A") {
$("#che_estado").prop("checked", "checked");
}
CierraPopup();
});
function CierraPopup() {
$("#popupBusquedaParroquia").modal('hide');//ocultamos el modal
$('body').removeClass('modal-open');//eliminamos la clase del body para poder hacer scroll
$('.modal-backdrop').remove();//eliminamos el backdrop del modal
}
Modal
<!-- Modal Escenario-->
<div class="modal fade" id="popupBusquedaParroquia" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Cerrar</span></button>
<h4 class="modal-title" id="myModalLabel">Busqueda de Parroquias</h4>
</div>
<div id="BusquedaParroquia" class="modal-body">
<form role="form">
<div class="form-group">
<label for="stock_bodega">Busqueda por:</label>
<select class="form-control" style="width: 40%" id="stock_bodega">
<option>Nombre</option>
</select>
<label for="texto_buscar">Texto a Buscar:</label>
<input type="text" class="form-control" id="texto_buscar">
</div>
<div style="position: relative; overflow: auto; width: 100%; height: 200px;" class="dataTables_scrollBody">
<table style="width: 100%;" id="busqueda_parroquia" class="display nowrap dataTable no-footer" cellspacing="0" width="100">
<thead>
<tr>
<th>Codigo</th>
<th>Nombre</th>
<th>Estado</th>
</tr>
</thead>
<tbody>
<tr>
<td>001</td>
<td>La Troncal</td>
<td>A</td>
</tr>
<tr>
<td>002</td>
<td>San Joose</td>
<td>A</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Seleccionar</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div> <!-- Modal Escenario-->