Problem with moment.js and datatable.js

Problem with moment.js and datatable.js

vetridazeworksvetridazeworks Posts: 11Questions: 5Answers: 0

I have column in the table which has date time field which needs to be sorted. As per most suggestions, moment.js is the plugin which is suggested to use for it. I had placed the plugin in the following order


// Datatable.js plugin

This is implemented in visualforce page, salesforce and when the page loads, I always get the following script error in the console

Uncaught TypeError: Cannot read property 'moment' of undefined
at HTMLDocument.<anonymous> (CPPListView?sfdc.tabName=01r4E000000DZav:11665)
at fire (jquery-1.12.4.js:3232)
at Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362)
at Function.ready (jquery-1.12.4.js:3582)
at HTMLDocument.completed (jquery-1.12.4.js:3617)

All solution for this? and its really urgent!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Have you included both Moment.JS and the DataTables / Moment plug-in?

    We'd need a link to the page showing the issue to be able to help resolve it.

    You'll be able to see it working correctly here.

    Allan

  • vetridazeworksvetridazeworks Posts: 11Questions: 5Answers: 0

    Hey Allan,

    Thanks for the reply! Here is the order the script is placed in the page


    <script type="text/javascript" src="{!$Resource.JqueryDataTable}"></script>// Datatable.js
    <script type="text/javascript" src="https://cdn.datatables.net/plug-ins/1.10.12/sorting/datetime-moment.js"></script>

    So the order is moment.min.js, datatable.js, datetime-moment.js! any issue?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Nope - that looks fine to me. I'd need a link to a page showing the issue to be able to help.

    Allan

  • vetridazeworksvetridazeworks Posts: 11Questions: 5Answers: 0

    Hi Allan,

    I can't give you the page link, since it needs authentication for Salesforce login! but is it possible for us to get into a call, may be teamviewer so that you can take control to look at it!

    Thanks,
    Vetri

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Yes, that would be something that would be covered by the priority support packages.

    Allan

  • vetridazeworksvetridazeworks Posts: 11Questions: 5Answers: 0

    Hey Allan,

    I figured out the issue! it is because of the jQuery conflict happened in the visualforce page caused the problem!

    I have few question! Here is the datetime format which I want to sort! "10/08/2017 02:49:01 AM" in the columndef I had given the type as "date-uk"? but still the column is not getting sorted

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    The Moment documentation shows all of the options that are available.

    Allan

This discussion has been closed.