0

I'm using AngularJS ng-repeat to display a chat view with a history of multiple days. To make the chat easier to read I want to add headers when there is a pause of some hours between two messages. (Like you may know it from mobile messenger apps.)

I know this could be done by grouping them and I'm aware of groupBy:. However groupBy: only allows to group by some value of the object, but I need to group it by similar timestamps. (Like grouping dates together when delay between them is less then one hour.)

Is there a simple way to realize that?

miho
  • 11,765
  • 7
  • 42
  • 85
  • same post as here: http://stackoverflow.com/questions/23493063/angular-ng-repeat-conditional-wrap-items-in-element-group-items-in-ng-repeat – Laurent May 21 '15 at 06:06
  • in the post you linked they are grouping by keys like "alpha", "beta", "gamma" - i don't see the relation to this question where we don't have static keys for sorting – miho May 21 '15 at 06:09

1 Answers1

-2

You can use custom filter as groupBy parameters

ng-repeat="chat in chats | customFilter:100"

CustomFilter as per example in angular grouping filter

app.filter('customFilter', function(){
return function(items, timing) {
  var groups = [],
     inner;
  for(var i = 0; i < items.length; i++) {
     //do timestamp grouping
     {
        inner = [];
        groups.push(inner);
     }
     inner.push(items[i]);
  }
  return groups;
 };
 });
Community
  • 1
  • 1
kwangsa
  • 1,701
  • 12
  • 16