d.date and d.images return undefined in ?format=datatables but not with ?format=json
TheNerdy97 opened this issue · 1 comments
TheNerdy97 commented
When I use api/fresh/?format=datatables two of my values that are not defined in the column but for a child row stop working even though this problem doesn't appear in api/fresh/?format=json but in this case, the sorting becomes quite buggy.
I'm pretty sure it's not anything else but a problem with my javascript, as the values do return with my Ajax response.
// Formatting function for row details - modify as you need //
function format ( d ) {
// `d` is the original data object for the row
return ('<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
'<tr>' +
'<b>' +
d.code +'<br></br>' +'Last Updated ('+ d.date + ')' +
'</b><br><br>' +
'<td>' +
d.images +
'</td>' +
'</tr>' +
'<tr>' +
'</tr>' +
'</table>')
}
$(document).ready(function() {
var table = $('#Fresh').DataTable( {
processing: true,
serverSide: true,
ajax:{
url:'api/fresh/?format=datatables',
dataSrc: 'data'
},
columns: [
{ data: "code" },
{ data: "orbs",
render: function ( data, type, row ) {
return '<img src=" static/images/items/orb.png " width="22" height="22" styleL="padding-bottom:3px;" /> '+ data;
} },
{ data: "price",
render: function ( data, type, row ) {
return '$'+ data;
} },
],
initComplete: function( settings, json ) {
this.api().rows().every( function () {
this.child( format(this.data()) ).show();
});
}
} );
} );
TheNerdy97 commented
Making the 'date' and 'images' always serialized fixed the issue.