MVC 5 server side Enum and DateTime problem
MVC 5 server side Enum and DateTime problem
Hello guys,
I started using DataTables with cliente side processing. However the amount of data is huge so I had to change it to server side processing to cope with all the records. I've managed to do the sort, filtering and paging and now it works wonderfully.
However I now have a problem with Enum and DateTime values.
The Enum values are shown as the int value instead of the description:
public enum StatusCustomer
{
Active = 0,
Inactive = 1
}
and the dates are showing as /Date(1448022404910)/
This is the code I use to init the DataTable:
var oTable = $('#tableCustomers').DataTable({
"bProcessing": true,
"bServerSide": true,
"bUseRendered": false,
"bDeferRender": true,
"ajax": {
"type": "POST",
"url": rootPath + 'Customers/GetCustomers',
"contentType": 'application/json; charset=utf-8',
'data': function (data) {
return data = JSON.stringify(data);
}
},
oLanguage: {
sProcessing: "<div class='progress margin-bottom-0'><div class='progress-bar progress-bar-striped active' style='width: 100%'></div></div>"
},
"columns": columnNames,
"order": [0, "asc"],
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
var oSettings = (this.fnSettings) ? this.fnSettings() : this;
AddActionBarToDataTable(nRow, aData, iDisplayIndex, actionBarView);
FormatDates(nRow, aData, iDisplayIndex);
return nRow;
},
"initComplete": function () {
InitComplete(this);
}
});
As you can see I tried to format the date using the fnRowCallback
method but I don't seem to be able to make it work because I don't know the column index, since the columns position can change:
function FormatDates(nRow, aData, iDisplayIndex)
{
var DateOfBirth = new Date(parseInt(aData["DateOfBirth"].replace("/Date(", "").replace(")/", ""), 10));
$('td:eq(3)', nRow).html(DateOfBirth.getMonth() + 1 + "/" + DateOfBirth.getDate() + "/" + DateOfBirth.getFullYear());
}
I can't hardcode the 3 into the td.
As for the Enum part I have no ideia of what I can do to solve it.
Thanks in advance for your help.