$fn.dataTables.moment
$fn.dataTables.moment
antoniocib
Posts: 277Questions: 62Answers: 1
Hi guys i've a little problem with moment.js
(function($){
$(document).ready(function() {
$.fn.dataTable.moment('DD,MM,Y');
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.scrivania1.php',
table: '#scrivania1',
This is my code JS
And this is my code HTML (where i import the js files)
<script type="text/javascript" charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/plug-ins/1.10.20/sorting/datetime-moment.js"></script>
<script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/plug-ins/1.10.19/dataRender/datetime.js"></script>
<script type="text/javascript" charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script type="text/javascript" charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/buttons/1.6.1/js/buttons.html5.min.js"></script>
<script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/moment-2.18.1/jszip-2.5.0/pdfmake-0.1.36/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-flash-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/kt-2.5.1/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sp-1.0.1/sl-1.3.1/datatables.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/dataTables.editor.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/table.scrivania1.js"></script>
I think I imported everything you need but I always get the error that $ .fn.dataTable.moment ();
is not a function how should I do?
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
My guess is you are loading the two Datatables plugins, lines 2 and 3 before loading Datatables on line 7. Try moving 1-3 to the end of your includes.
I don't see it but I assume you are loading jquery.js.
Kevin
Actually I just looked again and you are loading jquery on line 7 along with moment.js so the one you are loading in line 1 duplicates the one in line 7. You should remove line 1 in that case. Click on the link in line 7 and you will see what is being loaded. You have some other duplicates like PDFMake.js.
Load order is important and not duplicating JS and CSS loads is important. jQuery is need for the other libraries to load. So line 7 should be first followed by the others that are not included in line 7.
Kevin
@kthorngren can you write me the libraries that I have to import?
I notice you're using Editor. I'm not seeing you registered as a user.
Colin
It looks like your username didn't populate in one of our database tables for some reason, but I do see the trial license on your account.
Could you let me know which page you downloaded Editor from so I can see if I can track that error down please?
Thanks,
Allan
https://editor.datatables.net/generator/index from this page,but now can u help me?
Have you tried Kevin's suggestions? See this example - ensure same order as those sources there.
Colin
i used this library
but if i add
$fn.dataTables.moment();
Console:
SCRIPT438: The object does not support the 'moment property or method'
datatables.min.js (14,31040)
Open the CDN link. You will see a list of the included libraries. Specific to using moment you have
jQuery 3.3.1, Moment 2.18.1
.Since you are loading jQuery.js in this file it should be loaded first. It has moment.js included so you don't need to load it separately like line 1 in your first post. These two lines:
require both jquery.js and datatables.js to be loaded. So place them after you load these, for example:
You have other duplicates like PDFMake. You are loading them both in the compiled CDN and individually. Remove all the duplicated individual lines.
If you still have difficulties then please post a link to your page or build a test case replicating the problem so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
You will want to do the same with your CSS. Make sure you are duplicating them.
Kevin
http://live.datatables.net/yevumeba/1/ this is my table with js and html
I added the Editor CSS and JS that will work in this environment. Uncommented
$.fn.dataTable.moment('DD,MM,Y');
and don't see the console errors:http://live.datatables.net/zunogaga/1/edit
The ajax calls don't work. But if you want to add an example of your data you can get the JSON response from your site using the browser's network inspector and then use
data
to add the data to Datatables, like this example. OR you can just populate with data you make up.Kevin
@kthorngren https://damoratraffico.netsons.org/forse/scrivania1.html
look the column 'Data di Scarico' not work,dont order the date correctly
The datetime format you are specifying with
$.fn.dataTable.moment('DD,MM,Y');
does not match the format in your table:22/03/2020
. The Moment.js docs provide the datetime format specs. According to the docs you need$.fn.dataTable.moment('DD/MM/YYYY');
.Kevin
Oohh thanks Kevin i'm a really idiot, thank u !!!