Aanchal Aanchal - 2 months ago 9x
AngularJS Question

how to sort a table on basis of date of Birth when using angular js

I want to sort my table on the basis of date of Birth. I am using angular js in my code but it is not working as it is sorting the date column as if date is a string. I am using below code for sorting-

<a href="#" ng-click="sortType = 'dob'; sortReverse = !sortReverse">
Date of birth
<span ng-show="sortType == 'dob' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
<span ng-show="sortType == 'dob' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>

I have created a plunker here-

Can any one tell me how can I achieve that?


You should define the date of births as Date objects, and then use formatters to display the correct format in the view

"dob": new Date(1980, 0, 12)

See https://plnkr.co/edit/1Yupcexjb2DOJinTyTds?p=preview