I have encountered an issue with my application that I am struggling to solve: I want to format dates in my data table using Moment.js like I have done in the following script:
$().ready(function() {
const FROM_PATTERN = 'YYYY-MM-DD HH:mm:ss.SSS';
const TO_PATTERN = 'DD/MM/YYYY HH:mm';
// list of 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 am facing is the error message
$.fn.dataTable.render.moment is not a function
. I am using Laravel 8.54 with laravel-mix
. Here is my app.js
file 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 am reaching out for help because I have searched online but most solutions do not involve npm. Has anyone else encountered this issue before? Thank you in advance.