简体   繁体   English

$.fn.dataTable.render.moment 不是 function 和 npm

[英]$.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:我在我的应用程序中遇到了一个我无法解决的基本问题:我想像我在这个脚本中所做的那样使用 moment 在我的数据表中格式化日期:

$().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 .我遇到的问题是我收到此错误$.fn.dataTable.render.moment is not a function I'm using Laravel 8.54 with laravel-mix .我将 Laravel 8.54 与laravel-mix一起使用。 Here is my app.js where i load the libraries:这是我加载库的app.js

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?我在这里问是因为我看到很多主题都在处理这个问题,但没有一个使用 npm。有人必须处理这个问题吗? Thank in advance预先感谢

It's a plugin code from datatables.net这是来自 datatables.net 的插件代码

You can download it from here: https://cdn.datatables.net/plug-ins/1.11.5/dataRender/datetime.js您可以从这里下载: https://cdn.datatables.net/plug-ins/1.11.5/dataRender/datetime.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:$ .fn.DataTable.isDataTable不是函数 - Uncaught TypeError: $.fn.DataTable.isDataTable is not a function 错误 $.fn.DataTable.TableTools 不是 function - Error $.fn.DataTable.TableTools is not a function jquery 数据表 - $.fn.dataTable.ext.errMode 不是函数 - jquery Datatable - $.fn.dataTable.ext.errMode is not a function 将jest.fn()函数传递给酶浅渲染中的mapDispatchToProps - Pass jest.fn() function to mapDispatchToProps in enzyme shallow render 使用moment.js在render内部的函数中打印变量 - print variable inside function inside render with moment.js 在React中使用NPM Moment.js出现问题:moment__WEBPACK_IMPORTED_MODULE_2__format不是函数吗? - Problem using NPM Moment.js in React: moment__WEBPACK_IMPORTED_MODULE_2__format is not a function? 如何在条件下禁用 jquery 数据表中的渲染功能? - How to disable the render function in jquery datatable with condition? 如何在数据表中呈现来自`dataSrc` function 的列? - how to render columns from `dataSrc` function in datatable? 为什么 npm run 会导致错误:“Router.use() requires a middleware function but a &#39; + gettype(fn)”? - Why does npm run result in the error: “Router.use() requires a middleware function but a ' + gettype(fn)”? 调用函数时,“fn()”是否与“fn()”区别对待? - Is “fn ()” treated differently to “fn()” when invoking a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM