Cannot Sort when using Custom DataTypes, Server Side
Cannot Sort when using Custom DataTypes, Server Side
I create a Live.Datatable here but it does not reflect the issue. (http://live.datatables.net/qakuwiri/2)
When I click on the table headers to Sort, it works fine for String, ie column 0 (Name) but becuase i'm using complex objects for the next three columns, the Data in the column renders correctly usinf "data": "FermentableType.Name" but when i click on the Sort for that column i get the error 'Warning, Instance Property 'FermentableUse.Name' is not defind for Type 'Business.Fermentabe'
Most of my columns are string but i have a few joins to lookup tables. My JSON file looks like this.
[{
"Name": "2-Row",
"FermentableType": {
"Name": "Grain",
"ID": 2
},
"FermentableUse": {
"Name": "Base",
"ID": 2
},
"FermentableOrigin": {
"Name": "Canadian",
"ID": 2
},
"FermentablePH": {
"Name": "Base - 2-Row",
"PHLevel": 5.70,
"ID": 1
},
"Lovibond": 2.0,
"Potential": 1.036,
"MaxBatchPercentage": 100,
"Description": "Smooth, less grainy, moderate malt flavor. Basic malt for all beer styles.",
"ID": 365
}, {
"Name": "6-Row",
"FermentableType": {
"Name": "Grain",
"ID": 2
},
"FermentableUse": {
"Name": "Base",
"ID": 2
},
"FermentableOrigin": {
"Name": "Canadian",
"ID": 2
},
"FermentablePH": {
"Name": "Base - 6-Row",
"PHLevel": 5.79,
"ID": 2
},
"Lovibond": 2.0,
"Potential": 1.035,
"MaxBatchPercentage": 100,
"Description": "Moderate malt flavor. Basic malt for all beer styles.",
"ID": 366
}]
My JS
$(document).ready(function () {
var oTable = $('#datatab').DataTable({
"serverSide": true,
responsive: {
details: {
renderer: function (api, rowIdx, columns) {
var data = $.map(columns, function (col, i) {
return col.hidden ?
'<tr>' +
'<td>
' + col.title + ':' + '
</td> ' +
'<td>
' + col.data + '
</td>' +
'</tr>' :
'';
}).join('');
return data ?
$('<table/>').append(data) :
false;
}
}
},
"ajax": {
"type": "POST",
"url": '/Fermentables/DataHandler',
"contentType": 'application/json; charset=utf-8',
'data': function (data) { return data = JSON.stringify(data); }
},
"processing": true,
"paging": true,
"columns": [
{
"data": "Name", "mRender": function (data, type, full) {
return '<a href="Fermentables/Details/' + full.ID + '">' + data + '</a>';
}
},
{ "data": "FermentableType.Name" },
{ "data": "FermentableUse.Name" },
{ "data": "FermentableOrigin.Name" },
{ "data": "Lovibond" },
{ "data": "Potential" },
{ "data": "MaxBatchPercentage" },
{ "data": "Description" },
{
"data": "ID", "mRender": function (data, type, full) {
return '<a href="Fermentables/Edit/' + data + '"><i class="icon-edit"></i></a>';
}
},
{
"data": "ID", "mRender": function (data, type, full) {
return '<i class="icon-remove-sign" style="color:#FF0000;"></i>';
}
}
],
"order": [0, "asc"]
});
});