Created
July 2, 2015 21:01
-
-
Save ashteya/aa668aa914a3444da017 to your computer and use it in GitHub Desktop.
Group By Day In Collection-Repeat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .filter('groupByDayMonthYear', function($parse) { | |
| var dividers = {}; | |
| return function(input) { | |
| if (!input || !input.length) return; | |
| var output = [], | |
| previousDate, | |
| currentDate; | |
| for (var i = 0, ii = input.length; i < ii && (item = input[i]); i++) { | |
| currentDate = moment(item.Date); | |
| if (!previousDate || | |
| !currentDate.isSame(previousDate)) { | |
| var dividerId = currentDate.format('DDMMYYYY'); | |
| if (!dividers[dividerId]) { | |
| dividers[dividerId] = { | |
| isDivider: true, | |
| _id: dividerId, | |
| divider: currentDate.format('DD MMMM YYYY') | |
| }; | |
| } | |
| output.push(dividers[dividerId]); | |
| } | |
| output.push(item); | |
| previousDate = currentDate; | |
| } | |
| return output; | |
| }; | |
| }) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://gonehybrid.com/how-to-group-items-in-ionics-collection-repeat/