Getting undefined on click even
Getting undefined on click even
luispozoquerol
Posts: 3Questions: 2Answers: 0
Hello everybody,
For some reason ONClick even (see function below I get answer: "undefined" Its like row is not being found. Need some help please.
$(document).ready(function() {
var table = $('#myTable').DataTable({
"destroy": true,
"language": {
"url": "./language/Spanish.json",
},
"scrollY": "300px",
"scrollCollapse": true,
"paging": false,
'info': false,
"ajax": {
url: '/api/pedidos',
dataSrc: '',
type: 'GET'
},
"columns": [
{data: 'id_usuario'},
{data: 'ipn'},
{data: 'nombre'},
{data: 'anulado'},
],
});
$('#myTable tbody').on('click', 'tr', function () {
var data = table.row( this ).data();
alert( 'You clicked on '+data[0]+'\'s row' );
} );
});
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It looks fine. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
You are using array notation
data[0]
to access your data. But you definedcolumns.data
which means your data is an object. Try this:Kevin
Thank you! Mr. kthorngren.
It works fine now