datetime-moment with multiple tables

datetime-moment with multiple tables

dr_bartodr_barto Posts: 4Questions: 2Answers: 0

I just found the datetime-moment plugin which is a great help for my current problem -- sorting tables based on localized dates. Thanks for that!

However, I don't quite understand the usage of it: Apparently I cannot configure a specific column of a specific table to use a certain format -- this is done globally, and the order of $.fn.dataTable.moment calls seems to reflect the order of columns, as in the example:

$.fn.dataTable.moment( 'HH:mm MMM D, YY' );
$.fn.dataTable.moment( 'dddd, MMMM Do, YYYY' );

Now I have a single-page app with lots of DataTables, which use multiple different date formats. Should I call $.fn.dataTable.moment before each table's DataTable initialization to specify the date format used in that table? Is there a chance that these global formats are applied in the wrong order (since the sequence of table creation is decided upon at runtime), causing my sorting functionality to break?

A simple sample to clearify my question: assume I have three tables, two (T1 and T2) with format LL (e.g. April 1st, 1999) and one (T3) with format LLL (e.g. April 1st 1999, 8:00 AM). Would the following code work, regardless of the sequence the setup methods are called?

function setupT1() {
  $.fn.dataTable.moment('LL');
  $('#T1').DataTable();
}
function setupT2() {
  $.fn.dataTable.moment('LL');
  $('#T2').DataTable();
}
function setupT3() {
  $.fn.dataTable.moment('LLL');
  $('#T3').DataTable();
}
This discussion has been closed.