I need to get an id from the json object in the button's function. If I try to access directly the id I get undefined
(not the error/warning) but If I try to access the object I can see it without problem (the id and the rest of the data).
var table = $('#example').DataTable( {
serverSide: true,
dom: 'Bfrtip',
ajax: '/get?op=2',
columns: [
{ data: 'id' },
// more columns
],
buttons: [
{
text: 'New',
action: function ( e, dt, node, config ) {
window.location.href = '/url?op=new'
}
},
{
text: 'Modify',
action: function ( e, dt, node, config ) {
window.location.href = '/url?op=modify&id=' + dt.row( { selected: true } ).id() )
},
enabled: false
},
{
text: 'Delete',
action: function ( e, dt, node, config ) {
},
enabled: false
}
],
select: true
} );
I can access the json object doing this:
alert( JSON.stringify(dt.row( { selected: true } ).data()) );
// {"id":1,"key":"value","etc":"etc"}
That's working, I can see the object in the alert.
alert( dt.row( { selected: true } ).id() ); // undefined
alert( JSON.stringify(dt.row( { selected: true } ).id()) ); // "undefined"
alert( JSON.stringify(dt.row( { selected: true } ).data()[0]) ); // undefined
This is not working, I can see undefined
instead of the integer in the alert.
I tried many more things that I can't even remember but none is working...
What Am I doing wrong?