AngularJS Infinite Scrolling with lots of data

后端 未结 6 815
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 01:05

So I\'m trying to create an infinite scrolling table using AngularJS, similar to this: http://jsfiddle.net/vojtajina/U7Bz9/

The problem I\'m having is that in the jsfidd

相关标签:
6条回答
  • 2021-01-30 01:20

    I like the angular-ui implementation ui-scroll...

    https://github.com/angular-ui/ui-scroll

    ... over ngInfiniteScroll. The main difference with ui-scroll from a standard infinite scroll is that previous elements are removed when leaving the viewport.

    From their readme...

    The common way to present to the user a list of data elements of undefined length is to start with a small portion at the top of the list - just enough to fill the space on the page. Additional rows are appended to the bottom of the list as the user scrolls down the list.

    The problem with this approach is that even though rows at the top of the list become invisible as they scroll out of the view, they are still a part of the page and still consume resources. As the user scrolls down the list grows and the web app slows down.

    This becomes a real problem if the html representing a row has event handlers and/or angular watchers attached. A web app of an average complexity can easily introduce 20 watchers per row. Which for a list of 100 rows gives you total of 2000 watchers and a sluggish app.

    Additionally, ui-scroll is actively maintained.

    0 讨论(0)
  • 2021-01-30 01:20

    It seems that http://kamilkp.github.io/angular-vs-repeat would be what you are looking for. It is a virtual scrolling directive.

    0 讨论(0)
  • 2021-01-30 01:26

    Check out virtualRepeat from Angular Material

    It implements dynamic reuse of rows visible in the viewport area, just like ui-scroll

    0 讨论(0)
  • 2021-01-30 01:29

    A couple of things:

    1. "Infinite scrolling" to "1,000,000" rows is likely to have issues regardless of the framework, just because you've created millions and millions of DOM nodes (presuming you have more than one element in each record)

    2. The implementation you're looking at doing with <li ng-repeat="item in items">{{item.foo}}</li> or anything like that will have issues very quickly for one big reason: {{item.foo}}} or any ngBind like that will set up a $watch on that field, which creates a lot of overhead in the form of function references, etc. So while 10,000 small objects in an "array" isn't going to be that bad... 10,000-20,000 additional function references for each of those 10,000 items will be.

    What you'd want to do in this case would be create a directive that handles the adding and removing of DOM elements that are "too far" out of view as well as keeping the data up to date. That should mitigate most performance issues you might have.

    ... good infinite scrolling isn't simple, I'm sorry to say.

    0 讨论(0)
  • 2021-01-30 01:35

    You may try using ng-infinite-scroll :

    http://binarymuse.github.io/ngInfiniteScroll/

    0 讨论(0)
  • 2021-01-30 01:38

    So turns out that the ng-grid module for AngularJS has pretty much exactly what I needed. If you look at the examples page, the Server-Side Processing Example is also an infinite scrolling list that only loads the data that is needed.

    Thanks to those who commented and answered anyway.

    Latest URL : ng-grid

    0 讨论(0)
提交回复
热议问题