1

Currently I am using angular-ui/ui-scroll to populate the list of items in the table.

Is there a way I can get the list of all visible items that are being rendered in the ui using ui-scroll?

I was using adapter.topVisible and adapter.bottomVisible to get the top visible item and bottom visible item. But not sure about getting all the items in between them

georgeawg
  • 48,608
  • 13
  • 72
  • 95

1 Answers1

1

Get the indexOf the top item and get the indexOf bottom item, and then that should give you all the visible item indexes (between top and bottom).

Axar
  • 521
  • 1
  • 3
  • 11
  • Hi, thanks for your reply. Can you please be more specific in getting all the visible item indexes. Not sure if I followed you correctly. Any piece of code that illustrates your answer would be nice to have. Thank you – Pradyumna Ravuri Jun 25 '18 at 19:35
  • I've not worked with ui-scroll so I can't help you with code unless you make me a plunker. If you're saying you have a top and bottom items, and you have the array of items then you need to get the index of the top item and index of the bottom item, and everything in between should be what's visible. Assuming they are in order as visible. – Axar Jun 25 '18 at 19:37
  • Your example isn't very good because you're not storing anything you get. So I don't know how you're supposed to get data. From the way I see it, you have 4 very important information available, topItem, topScope, topElement, top.$index, you can use this value and query the back-end for all items that fall within the top and bottom. And there you have the visible items. Does that make sense? Just call the datasource.get() method to return you from index=top and count = bottom-top. Alternatively you have the topElement and use jquery to fetch all elements until you hit bottomElement. – Axar Jun 25 '18 at 21:57
  • Yep I really like the first idea you suggested make an api call with index = top and count = bottom-up. The reason being i am not storing is, ui-scroll maintains buffer to get the items internally. Not sure if there is a way to access buffer and loop over it instead of making an api call ? – Pradyumna Ravuri Jun 25 '18 at 22:27
  • I don't see any exposed API in the library that allows access to this information. Making an api call is fine, you can attempt temporarily caching as well.you might even be able to extend the scroller and introduce a get visible items directive, all it needs is the dataSource and adapter information. – Axar Jun 25 '18 at 22:43
  • Thanks for the suggestion I will go with the api call. – Pradyumna Ravuri Jun 26 '18 at 00:03