question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: Expose some method for infinite scroll/pagination/scroll bottom

See original GitHub issue

I’ve been trying to implement infinite scroll with ember-power-select, and none of the available public API’s allow a clean implementation. The closest I got was using the onopen hook, but since the list is not rendered when onopen fires the implementation looks like this (CoffeeScript… don’t judge…):

onopen: (options, e) ->
  Ember.run.later =>
    element = $(e.target).parents('.ember-basic-dropdown').find('ul')[0]
    element?.addEventListener 'scroll', =>
      if element.scrollHeight - element.scrollTop is element.clientHeight
        @loadMore()
  , 500

There’s two issues with this approach:

  • The event target is sometimes the selected item span, sometimes a div (which isn’t a deal breaker)
  • The 500 ms delay is arbitrary, and subject to race conditions. Scheduling it afterRender or run.next didn’t work (which is a deal breaker)

The way I see it, there’s three potential solutions:

  • Moving onopen to fire after the list renders
  • Exposing an afteropen event
  • Exposing a scrollbottom event

Implementing a scrollbottom isn’t too difficult. I got it mostly working by simply dropping this in didInsertElement at addon/components/power-select/options.js:

    this.element.addEventListener('scroll', (e) => {
      if(this.element.scrollHeight - this.element.scrollTop == this.element.clientHeight){
        this.send('scrollBottom');
      }
    });

I might be able to throw some time at this if the maintainer(s?) would like to give some direction.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:9
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
luketheobscurecommented, Jul 15, 2017

We worked around it by using the afterOptionsComponent hook. We’ve got a component that renders a “Load more…” button that loads in the next page of records. It’s working really well for us.

1reaction
PrzemoRevolvecommented, Jun 28, 2019

In case anyone is interested - we’re managed to achieve pagination by extending power-select/options in a custom component:

//scroll-aware-options.ts
import Options from 'ember-power-select/components/power-select/options';

export default class ScrollAwareOptions extends Options {
  onScroll = () => {}

  didInsertElement() {
    super.didInsertElement();
    this.element.addEventListener('scroll', this.onScroll, { passive: true });
  }

  willDestroyElement() {
    super.willDestroyElement();
    this.element.removeEventListener('scroll', this.onScroll);
  }

}

and then we’ve used a little trick with optionsComponent attribute of power-select:

// our-select.hbs
{{#power-select
  // ...some attributes
  optionsComponent=(component "scroll-aware-options" onScroll=(action "onScroll"))
}}

This way we didn’t have to fork/copy-paste anything to make it work. Hope it helps somebody 😁

Read more comments on GitHub >

github_iconTop Results From Across the Web

Infinite Scroll: Let's Get To The Bottom Of This
With infinite scrolling, social websites are doing their best to expose as much information as possible to the user.
Read more >
Endless Scrolling with AdapterViews and RecyclerView
This is done by triggering a request for more data once the user crosses a threshold of remaining items before they've hit the...
Read more >
Infinite Scrolling With React - Tutorial - YouTube
In this video I will be breaking down exact. ... Infinite scrolling is really just a fancy type of pagination that will paginate...
Read more >
How to implement infinite scroll pagination in Flutter
The application starts by fetching the first ten posts. As the user scrolls down the page, it fetches more posts. Notice the position...
Read more >
Infinite Scrolling with Android Paging Library and Flow API
data: the actual data. ... nextKey: the index of the next page or null if this is the last page. Error. which represents...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found