Using DataTable.datetime('DD/MM/YY');

Using DataTable.datetime('DD/MM/YY');

csyucsyu Posts: 14Questions: 2Answers: 1
edited May 18 in DataTables 2

Error messages shown:
TypeError: i.datetime is not a function

Description of problem:
I'm am looking to have Datatables render a datetime column so that I can sort it correctly.

When I add DataTable.datetime('DD/MM/YY'); to my Vue page, I get the error above.

My full imports:

import moment from 'moment';
import DataTable from 'datatables.net-vue3';
import DataTablesLib from 'datatables.net';
import 'datatables.net-select';
import 'datatables.net-responsive';

DataTable.use(DataTablesLib);
DataTable.datetime('DD/MM/YY');

Thank you

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    It is a method of the datatables.net package. Try DataTablesLib.datetime.

    Allan

  • csyucsyu Posts: 14Questions: 2Answers: 1
    edited May 19

    Thanks Allan.

    Not sure why it's still not working. I now have this code:

    import moment from 'moment';
    import DataTable from 'datatables.net-vue3';
    import DataTablesLib from 'datatables.net';
    import 'datatables.net-select';
    import 'datatables.net-responsive';
    DataTable.use(DataTablesLib);
    DataTablesLib.datetime('DD/MM/YY');
    

    But I get the warning via a browser alert:

    DataTables warning: Formatted date without Moment.js or Luxon - https://datatables.net/tn/17
    

    Moment.js is loaded properly on the page because I can do this successfully:

    render: function (data:any) {
      return moment(data).format('MMM DD YYYY');
    }
    

    Any thoughts on if the DataTablesLib has another dependency to make this work?

Sign In or Register to comment.