Datatable is not sorting with date in dd/MM/yyyy format
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
I have also noticed this issue.
any solution ??
My issue was resolved by adding this:
'columnDefs': [
{ 'type': 'date', 'targets': 2 }
],
@brussonOC it didn't work for me
@brussonOC not work with me
not worked for me to @l-lin PLZ can you put some light on it plz
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.
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;
}
}
]
};