Tablesorter Task - Dates

I know there were some questions about this, but I cannot fix my problem.

I upload the CSV file to tablesorter, but one of my columns is the dates (December 23, 2009). But they are sorted as December 2, December 23, December 3, December 31.

Does anyone know a solution? Here you can see the problem , this is the table below. Thanks for that in advance!

<script type="text/javascript" charset="utf-8">
  $(document).ready(function() 
      { 
          $("#tablesorter-demo2").tablesorter({ widgets: ['zebra'] });
      } 
  );
 </script>

-

table width = "871" border = "0" cellpadding = "0" cellspacing = "1" class = "TableSorter" ID = "TableSorter-demo">

$row = 1;
$handle = fopen("csv/canadatransactions.csv",

"g"); while (($ data = fgetcsv ($ handle, 1000, ","))! == FALSE) {$ num = count ($ data); $ Lines ++;

                if ($row == 2)
               {
                   echo "<thead>\n<tr>\n";

                   echo "<th class=\"header\">" . $data[1] .

"\ ";//          ". $data [0]." \ ";//                        " ". $data [2]." \ ";//                        " ". $data [3]." \ ";//                        " ". $data [4]." \ ";//         " ". $data [5]." \ ";//       " ". $data [6]." \ ";//

                   echo "</tr>\n</thead>\n<tbody>";
               }

               else
               {
                   echo "<tr class=\"even\"";
                   echo ">\n";
                   echo "<td>" . $data[1] . "</td>\n";
    echo "<td>" . $data[0] . "</td>\n";
    echo "<td>" . $data[2] . "</td>\n";
    echo "<td>" . $data[3] . "</td>\n";
    echo "<td>" . $data[4] . "</td>\n";
    echo "<td>C$ " . $data[5] . "</td>\n";
    echo "<td>C$ " . $data[6] . "</td>\n";

                   $transactions = $row - 3;
 }
}
fclose($handle);
?>
            </tbody>
</table>
+5
3

. . , sorter:

<table>
<thead>
    <tr>
        <th>Id</th>
        ... other columns ....
        <th class="{sorter: 'isoDate'}">Date</th>
</tr>           
</thead>
<tbody>
... table body ....

, isoDate - , , tablesorter : usLongDate shortDate. , .

+1

If none of the default sorting options work, try using a custom parser and convert the date to the equivalent millisecond representation for sorting.

$.tablesorter.addParser({ 
    // set a unique id 
    id: 'dateMS', 
    is: function(s) { 
        // return false so this parser is not auto detected 
        return false; 
    }, 
    format: function(s) { 
        var d = Date.parse(s);
        if (isNaN(d)) {
           return -1;
        }
        return d;
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
});     

$(function() { 
    $("table").tablesorter({ 
        headers: { 
            6: { 
                sorter:'dateMS' 
            } 
        } 
    }); 
}); 
0
source

All Articles