Jose
Jose

Reputation: 1239

AngularJS conflit with limitTo and filter in ngrepeat

I have a ng-repeat with lot of keywords (> 100 000) that's why I use limitTo: but I would like to be able to search in ALL.

Search: <input ng-model="filter:queryKeywords" type="text" placeholder="Filter" autofocus>

<label ng-repeat="k in keywords | limitTo:totalDisplayed | orderBy | filter:queryKeywords">
   {{k}}
</label> 

<!-- Will load 100+ keywords -->
<button class="btn btn-primary" ng-click="seeMore()">See More</button>

The problem is my search only works for items that I can see.

I would like to search in all items (even the one that I can't display).

Thanks!

Upvotes: 3

Views: 2929

Answers (2)

gkalpak
gkalpak

Reputation: 48212

You should change the order of the filters, so that searching comes first (and thus applies to all data) and limiting/ordering come afterwards:

ng-repeat="k in keywords | 
           filter:queryKeywords |
           limitTo:totalDisplayed |
           orderBy"

Upvotes: 9

Onur Topal
Onur Topal

Reputation: 3061

Angular applies filters in order. Changing the order of the filters should fix your problem.

<label ng-repeat="k in keywords | filter:queryKeywords | limitTo:totalDisplayed | orderBy">

This means: First filter, then limit the results to totalDisplayed and finally order it.

Upvotes: 4

Related Questions