'$.fn.dataTable.render.moment is not a function with npm
I got a basic issue in my application that i can't solve : i would like to format date in my datatable using moment like i have done in this script :
$().ready(function() {
const FROM_PATTERN = 'YYYY-MM-DD HH:mm:ss.SSS';
const TO_PATTERN = 'DD/MM/YYYY HH:mm';
// liste des documents - INDEX
var listDocuments = $("#list-documents").DataTable({
processing:true,
serverSide:true,
scrollY:620,
autoWidth:true,
pageLength:25,
responsive:true,
scroller: {
loadingIndicator:true
},
ajax: {
url: $("#list-documents").attr('data-json')
},
columns: [
{data:'nom',name:'nom'},
{data:'uri',name:'uri',
"fnCreatedCell": function(nTd,sData,oData,iRow,iCol) {
$(nTd).html("<a href='" + oData.uri + "'>"+ oData.uri +"</a>")
}
},
{data:'updated_at',name:'updated_at',
render: $.fn.dataTable.render.moment(FROM_PATTERN,TO_PATTERN),
},
{data:'action',name:'action',orderable:false,searchable:false},
]
})
.on('draw',function() {
$("[data-toggle='tooltip']").tooltip()
})
})
The problem i had is that i got this error $.fn.dataTable.render.moment is not a function
. I'm using Laravel 8.54 with laravel-mix
. Here is my app.js
where i load the libraries :
require('./bootstrap');
$('.toast').toast('show')
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
window.$ = window.jQuery = require('jquery')
window.toastr = require('toastr')
require('moment')
require('../../node_modules/datatables.net/js/jquery.dataTables.js')
require('datetime-moment')
require('../../node_modules/datatables.net-bs4/js/dataTables.bootstrap4')
require('../../node_modules/jquery-ui/ui/widgets/autocomplete.js')
require('../../node_modules/jquery-ui/ui/widgets/sortable.js')
require('datatables.net-responsive')
I'm asking here because i saw many subjects treating this issue but none of these use npm. Does anyone has to deal with this issue ? Thank in advance
Solution 1:[1]
It's a plugin code from datatables.net
You can download it from here: https://cdn.datatables.net/plug-ins/1.11.5/dataRender/datetime.js
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jack Ting |