Error with buttons in rows
Error with buttons in rows
mldgato
Posts: 13Questions: 3Answers: 0
I have a table which shows the information I need, the problem is that at the time of clicking the buttons that I place in each row tells me that the variable where I save the datatable tells me that it is not a funsion.
The error that the browser console shows me is
TypeError: TablaLosAlumnos.row is not a function
This is my javascript code
$(document).ready(function()
{
var TablaLosAlumnos = $('#TablaLosAlumnos').dataTable(
{
"language":
{
"url": "//cdn.datatables.net/plug-ins/1.10.12/i18n/Spanish.json"
},
"ajax": "alumnobuscadorListado.php",
"pageLength": 50,
"columnDefs": [
{"targets": 0, "data": "CarnetAlumno", "searchable": true, "orderable": true},
{"targets": 1, "data": "ApellidosAlumno", "searchable": true, "orderable": true},
{"targets": 2, "data": "NombresAlumno", "searchable": true, "orderable": true},
{"targets": 3, "data": null, "searchable": false, "orderable": false, "defaultContent": "<button id='AdminAlumno' class='btn btn-success btn-xs'>Administrar <span class='glyphicon glyphicon-pencil'></span></button>"},
{"targets": 4, "data": null, "searchable": false, "orderable": false, "defaultContent": "<button id='FichaAlumno' class='btn btn-danger btn-xs'>Ficha <i class='fa fa-file-pdf-o'></i></button>"},
{"targets": 5, "data": null, "searchable": false, "orderable": false, "defaultContent": "<button id='BorrarAlumno' class='btn btn-warning btn-xs'>Eliminar <i class='fa fa-trash'></i></button>"}
]
});
$('#TablaLosAlumnos tbody').on( 'click', '#AdminAlumno', function()
{
var data = TablaLosAlumnos.row($(this).parents('tr')).data();
window.open("alumno.php?CarnetAlumno="+data['CarnetAlumno']);
});
$('#TablaLosAlumnos tbody').on( 'click', '#FichaAlumno', function()
{
var data = TablaLosAlumnos.row($(this).parents('tr')).data();
window.open("ficha.php?CarnetAlumno="+data['CarnetAlumno']);
});
});
The HTML
<table id="TablaLosAlumnos" class="table table-striped table-bordered table-hover table-condensed">
<thead>
<tr>
<th>Carnet</th>
<th>Apellidos</th>
<th>Nombres</th>
<th>Aministrar</th>
<th>Ficha</th>
<th>Eliminar</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Carnet</th>
<th>Apellidos</th>
<th>Nombres</th>
<th>Aministrar</th>
<th>Ficha</th>
<th>Eliminar</th>
</tr>
</tfoot>
</table>
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I found my error was instantiating in a bad way
Quickest solution is to change TablaLosAlumnos.row to $('#TablaLosAlumnos').DataTable().row so that you don't have the dependency on a variable.