mariuszfoltak / angular2-datatable

DataTable - Simple table component with sorting and pagination for Angular2
202 stars 183 forks source link

Date is not sorting #152

Open nandhuems opened 6 years ago

nandhuems commented 6 years ago

I have Date Format like "01-03-2018". but the angular2-datable is not sorting correctly. the date is sorting based on the first digit.

jmarlett93 commented 6 years ago

To sort by date you need to add parsing information in the template syntax that matches your date syntax. Table specifies "deliveryDate":

<table class="table table-condensed table-striped text-center" [(mfSortBy)]="deliveryDate" [(mfSortOrder)]="sortOrder" [mfData]="data" #mf="mfDataTable">

Header specifies with the "by" directive:

<thead><tr><th class="text-center"><mfDefaultSorter by="deliveryDate"><span>Order Date</span</mfDefaultSorter></th>

And in the tbody the crucial template parsing information:

<tbody><tr *ngFor="let item of mf.data"><td ><span>{{item.deliveryDate | date: 'MM-dd-yyyy'}}</span></td></tr></tbody>