Need Help with date sorting

Need Help with date sorting

Noodles12Noodles12 Posts: 113Questions: 41Answers: 2

I am using a datatable that has date column. I am trying to sort is by Date Ascending but it doesn't seem to work. It is not sorting properly. It places July 30 above Mar 5. Can you please help. Thanks. Here is my code -

<table class="row-border stripe dt-right dataTable no-footer dtr-inline" id="test" style="width: 100%;"><thead text-align="left"><tr><th>Event</th><th>City, State</th><th>Date</th></tr></thead>
<tbody>
<tr>
<td>My first event</th>
<td>Devnver,CO</th>
<td>Mar 4 - 7, 2024</th>
</tr>

<tr>
<td>My third event</th>
<td>Devnver,CO</th>
<td>Mar 5, 2024</th>
</tr>

<tr>
<td>My second event</th>
<td>Devnver,CO</th>
<td>Jul 30 - 31, 2024</th>
</tr>

<tr>
<td>My fourth event</th>
<td>Devnver,CO</th>
<td>Mar 5, 2024</th>
</tr>


$(document).ready(function() {
   $.fn.dataTable.moment( 'MM/DD/YYYY' );
$('#test').DataTable({
  responsive: true,
  paging: false,
  lengthChange: false,
fixedHeader: true,
columnDefs: [
  {
    targets: 2,
    type: 'date',
  }
],

order:[[  2, 'asc' ]]

 } );

} );

This question has an accepted answers - jump to answer

Answers

Sign In or Register to comment.