Unable to get value from selected row
Unable to get value from selected row
aarontharker
Posts: 41Questions: 11Answers: 0
var loc = $('#locations').DataTable( {
dom: "Bfrtip",
"pageLength":5,
ajax: {
url: "./controllers/locations.php",
type: "POST",
data: {
"id": frmID}
},
columns: [
{ data: "Locations.id",
visible: false },
{ data: "Customers.Name" },
{ data: "Services.Name" },
{ data: "Locations.Address1"},
{ data: "Locations.Address2"},
{ data: "Locations.Contact"},
{ data: "Locations.Suburb"},
{ data: "Locations.City"},
{ data: "Locations.State"},
{ data: "Locations.Country"},
{ data: "Users",
render: function ( data, type, row ) {
return data.firstname +' '+ data.lastname;
}
}
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
} );
loc.on( 'select', function ( e, dt, type, indexes ) {
if ( type === 'row' ) {
var locRow = loc.rows(indexes).data().pluck( 'Locations.id' );
$('#subform').show();
console.log(locRow);
}
} );
Can anyone see why this is not returning the Locations.id value from the table?
When I check the console log it is saying undefined.
I have tried using both 'Locations.id' and simply 'id' but neither way returns a value. Also tried making the column visible to see if that made a difference but it did not.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
{"data":[{"DT_RowId":"row_3","Locations":{"id":"3","Customer_id":"2","Service_id":"1",:
The Locations.id is obviously there in the JSON string being given to datatables.
See the Nested data example of the
pluck()
API docs for the answer. You need.pluck( 'Locations' ).pluck( 'id' )
.Kevin
@kthorngren Thanks Heaps