angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

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

Open menwn opened this issue 7 years ago • 8 comments

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>
`
    `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

menwn avatar Feb 08 '19 11:02 menwn

I have also noticed this issue.

brussonOC avatar Feb 27 '19 10:02 brussonOC

any solution ??

KerolosMalak avatar Mar 07 '19 18:03 KerolosMalak

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

brussonOC avatar Mar 08 '19 08:03 brussonOC

@brussonOC it didn't work for me

tarekmkassab avatar Mar 08 '19 10:03 tarekmkassab

@brussonOC not work with me

KerolosMalak avatar Mar 08 '19 21:03 KerolosMalak

not worked for me to @l-lin PLZ can you put some light on it plz

awais2080 avatar Mar 13 '19 06:03 awais2080

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.

menwn avatar Mar 13 '19 09:03 menwn

Hello, I think they have already closed this issue but I have an update in case it works for someone, in my case the date is in position 1 of my table and I solved it like this.

this.dtOptions = { order: [1, 'desc'], columnDefs: [ { targets: 1, render: function (data, type, row) { if (type === 'sort' || type === 'type') { return data.split('/').reverse().join(''); } return data; } } ] };

benjarmc avatar Mar 05 '24 01:03 benjarmc