samedi 27 décembre 2014

AngularJS ng-repeat filter performance: custom filter or ng-show / hide


tl;dr What's the optimal way to filter large lists in Angular?




This is mainly about performance.


I have an array of objects that I list with ng-repeat. There will be hundreds to thousands of items. I now need to filter the list based on either:



  • A. a single, simple property (e.g. number)

  • B. multiple conditions (some expression)


What option is best:



  1. use a custom filter

  2. use ng-show / ng-hide

  3. use ng-if

  4. don't filter in the view at all -- maybe use service + controller (?)

  5. use ReactJS (?)




Details about the usecase:



  • I want to bind most of the objects' properties with :: one time binding, though some properties need two-way binding (score for sorting)

  • The list will be sorted dynamically, on fields independent from the fields used for filtering. Items filtered out probably should not be included in the sorting

  • The filtering needs to be dynamic


So I found Ben Nadel's post http://www.bennadel.com/blog/2487-filter-vs-nghide-with-ngrepeat-in-angularjs.htm but my question is meant to address general, standard usecases.





Aucun commentaire:

Enregistrer un commentaire