question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable is not sorting with date in dd/MM/yyyy format

See original GitHub issue

I’m submitting a…


[ ] Bug report

Current behavior

The data table is not sorting with dates when they are formated as dd/MM/yyyy

Expected behavior

To sort correctly on the date column

Minimal reproduction of the problem with instructions

 `    <div *ngIf="api.coupon$ | async as allCoupons">
<div class="col ">
  <table datatable [dtOptions]="dtOptions"  class="table table-striped" style="font-size: 0.8rem;">
    <thead>
    <tr class="text-center">
      <th scope="col">Coupon Code</th>
      <th scope="col">Coupon State</th>
      <th scope="col">Issuance Channel</th>
      <th scope="col">Create Date</th>
      <th scope="col">Expire Date</th>
      <th scope="col">Number Of Redemptions</th>
      <th scope="col">Redemptions</th>
    </tr>
    </thead>
    <tbody>
    <tr class="text-center" *ngFor="let object of allCoupons">
      <td scope="col">{{object.couponCode}}</td>
      <td scope="col">{{object.couponState}}</td>
      <td scope="col">{{object.channel}}</td>

      <td
        scope="col">{{object.createDate | date: 'dd/MM/yyyy' }}</td>

      <td
        scope="col">{{object.expireDate }}</td>

      <td scope="col"> {{object.redemptions.length}}</td>

      <td>
        <div class="btn-group btn-group-sm w-100">
          <button type="button" class="w-100 btn btn-light fas fa-list-alt "
                  title="See Redemptions"
                  (click)="openRedeemModal(content,object.redemptions)">
          </button>
        </div>
      </td>
    </tr>

    </tbody>
  </table>
</div>
</div>`
    `dtOptions: DataTables.Settings = {};
    ngOnInit() {
    this.dtOptions = {
    columnDefs: [

    { targets: 3, type: 'date' }

       ]

   };`

##Demo:

https://angular-datatables-gitter-smpc8z.stackblitz.io/

https://stackblitz.com/edit/angular-datatables-gitter-smpc8z (editor)

Environment


- node version:v11.1.0
- angular version:7.2.4
- angular-cli version:7.3.0
- jquery version:3.3.22
- datatables version:1.10.13
- angular-datatables version:^7.0.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

4reactions
menwncommented, Mar 13, 2019

I have found a solution that works. I had a stack overflow question so I updated there with the solution. Here it is:

https://stackoverflow.com/a/54688603/807595

It basically needs a jquery plug in.

2reactions
brussonOCcommented, Mar 8, 2019

My issue was resolved by adding this: 'columnDefs': [ { 'type': 'date', 'targets': 2 } ],

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix sorting for Date format dd-mm-yyyy? - DataTables
I have datatables that contain of multiple column of date. But all the column date is not work perfectly for sorting asc and...
Read more >
Datatable date sorting dd/mm/yyyy issue - Stack Overflow
Date Sort - with a hidden element. Convert the date to the format YYYYMMDD and prepend to the actual value (DD/MM/YYYY) in the...
Read more >
jQuery : Datatable date sorting dd/mm/yyyy issue - YouTube
jQuery : Datatable date sorting dd/mm/yyyy issue [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] jQuery : Datatable ...
Read more >
Datatables - Order by date DD/MM/YYYY - CodePen
Insecure Resource. The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https....
Read more >
How to Sort Date in LWC Data table in DD.MM.YYYY Format?
Tried the above logic earlier and earlier , unfortunately its not working.. – SFDCLearner. May 3 at 11:49. @SFDCLearner ok that means ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found