Я получаю Json следующим образом:
[
{
"id":1,
"repDate":{
"offset":{
"totalSeconds":7200,
"id":"+02:00",
"rules":{
"fixedOffset":true,
"transitions":[
],
"transitionRules":[
]
}
},
"nano":880042000,
"year":2018,
"monthValue":4,
"dayOfMonth":25,
"hour":12,
"minute":58,
"second":53,
"month":"APRIL",
"dayOfWeek":"WEDNESDAY",
"dayOfYear":115
},
"hashrate":5114926.0
},
...more entries
]
Мне нужно отобразить дату в определенном формате: yyyy.mm.dd - hh.mm.ss.nnn
, поэтому я хотел бы создать пользовательскую переменную, но я не совсем уверен, где. Вот моя функция JS для получения json
и установки DataTables
. Я пытался создать строку в columnDefs
, но это не работает.
var table;
$(document).ready(function() {
table = $('#main-table').DataTable({
ajax: {
url: '/refresh',
dataSrc:''
},
paging: true,
lengthChange: false,
pageLength: 20,
stateSave: true,
info: true,
searching: false,
"columnDefs": [
{
"className": "text-center",
"targets": 0,
"data": "id",
},
{
"className": "text-center",
"targets": 1,
"data": "repDate.year" + "." + "repDate.monthValue" + "." + "repDate.dayOfMonth",
},
{
"className": "text-center",
"targets": 2,
"data": "hashrate",
}
],
"aoColumns": [
{ "orderSequence": [ "asc", "desc" ] },
{ "orderSequence": [ "asc", "desc" ] },
{ "orderSequence": [ "desc", "asc" ] }
],
"order": [[ 0, "asc" ]]
});
});
setInterval(function(){
table.ajax.reload(null, false);
}, 8000);