最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS conflit with limitTo and filter in ngrepeat - Stack Overflow

programmeradmin3浏览0评论

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!

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!

Share Improve this question asked Nov 28, 2014 at 9:41 JoseJose 1,2391 gold badge10 silver badges23 bronze badges 3
  • It's because the filter in in the template so it would apply to the rendered element only. You need a filter at the data level instead then you can control the limit from there too. angular UI grid would probably work perfectly here though its built in filter are quite good and affect the all data. – GillesC Commented Nov 28, 2014 at 9:46
  • Thanks for your help. Please could you show me an example, not sure to understand well. – Jose Commented Nov 28, 2014 at 9:47
  • Given the amount of keywords, perhaps you should also consider doing the search in the backend and returning only the limitTo keywords you want, that would send less data through the network and making the frontend to process less data too (of course, I'm assuming you have a backend you can modify, right?) – germanio Commented Sep 10, 2017 at 21:39
Add a ment  | 

2 Answers 2

Reset to default 9

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

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

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.

发布评论

评论列表(0)

  1. 暂无评论