Nagaraju
Nagaraju

Reputation: 1875

Tablesorter sorting issue when using date format with intitalsortorder

I am trying to sort the column of table that contains date in dd-mm-yyyy format. I am also trying to set the initialsortorder but it is generating numeric sort rather than date sort. There seems to be a issue when using headers along with initialsortorder in jquery tablesorter plugin.

I had tried the following:

$('#table').tablesorter({
     sortList: [[0,1]],
     dateFormat : "dd-mm-yyyy",
     headers: {   
              0: { sorter: 'shortDate' } 
            }
        });

The above code sorts initially but only in numeric format.

Another try:

 $('#table').tablesorter({
         //sortList: [[0,1]],
         dateFormat : "dd-mm-yyyy",
         headers: {   
                  0: { sorter: 'shortDate',sortInitialOrder: 'desc'} 
                }
            });

This one sorts according to date format specified but not sorting initially, it sorts only when the header(thead) is clicked.

Question: How to generate initial sort with date format included.

Upvotes: 2

Views: 1925

Answers (1)

Mottie
Mottie

Reputation: 86413

If you are using the original tablesorter (v2.0.5)

  • The sortInitialOrder can not be set within the headers option. It is a global option only.
  • dateFormat only accepts these options:
    • "us" - supports "mm-dd-yyyy" or "mm/dd/yyyy"
    • "uk", "dd/mm/yy" or "dd-mm-yy" - supports "dd-mm-yyyy" or "dd/mm/yyyy"

Here is a demo using the following code:

$('table').tablesorter({
    dateFormat: 'uk',
    sortInitialOrder: 'desc',
    headers: {
        0: { sorter: 'shortDate' }
    }
});

Upvotes: 2

Related Questions