Upload data into a table in a jquery-datatables , when I delete a row after using an event that is placed on a label in the following way " <a onclick='eliminar()'></a>
", this method is activated and it is eliminated by just clicking on any part of the row, I can notice that if I add a console.log()
within the function I use to delete the row, it prints me several times depending on the number of clicks I have given on the rows, the code is as follows:
$(function(){
cargarDatos();
});
// Cargo los datos en la tabla
//
function cargarDatos(){
var t = $("#luminariasAuditar").DataTable();
for (var i = 0; i < luminaria.length; i++) {
t.row.add([
luminaria[i].color,
luminaria[i].value,
'<a href="#?" onclick=\'eliminar();\' >X</a>'
]).draw(false);
}
}
// función con la que elimino las filas
//
function eliminar () {
var t = $("#luminariasAuditar").DataTable();
$('#luminariasAuditar tbody tr').on('click', function (event) {
console.log("clics");
t.row(this).remove().draw();
});
};
The intention is to delete the row only when you click on the " X "