Collection-repeat with orderBy, filter and track by not working


#1

Hi everyone

I’m trying to display a list of movies, ordered by “listed_at” (in reverse) there’s also a search on top hence the filter.

Now I’m also adding an ion-option-button which makes the list item swipeable to show a remove button.
The remove button calls a function which makes an API call to remove the movie from the list (this works), the list should also be updated to reflect te removal of the item. So I also pass the $index of the movie item and splice the movies array to remove it.

The “track by” should automatically update the list when an item is spliced.

Here’s the collection-repeat I’m using:
<ion-item collection-repeat="item in movies | orderBy:'listed_at':true | filter:search track by $index" class="item-thumbnail-left item-icon-right" href="#">

Here the “track by” doesn’t seem to work (after removing a movie, the list isn’t updated)

When I try collection-repeat without the orderBy it does work:
<ion-item collection-repeat="item in movies | filter:search track by $index" class="item-thumbnail-left item-icon-right" href="#">

What’s going on here? Is this a bug?

Any help welcome!


#2

I think performance wise it is a better solution to sort the movies array beforehand right after recieving it from the backend. Then no unnecessary sorting will be going on. As i understand you don’t need the sorting to change?
This should also resolve your issue.


#3

Thanks for your reply!

Your suggestion will fix my issue :wink:
Question still remains though, why doesn’t using orderBy, filter and track by in collection-repeat work here?