Giter VIP home page Giter VIP logo

ember-power-select-infinity's Introduction

ember-power-select-infinity

To Infinity & Beyond

This addon provides a power select which uses occlusion rendering to infinitely load and search for a large list of items.

Compatibility

  • Ember.js v3.24 or above
  • Ember CLI v3.24 or above
  • Node.js v12 or above

Installation

ember install @gavant/ember-power-select-infinity

Usage

To use power-select-infinity you just declare it in a template. Both search and loadMore must return a promise to that power-select-infinity can display the loading indicator. The paging is left up to you, since some API's use different formats for paging. Some API's declare page=1, others take in the last items ID. Either way, power-select-infinity just provides a loadMore action where you can load data however your API requires.

If your using ember-cli-sass in your project, an import statement will automatically be added to your project.

Your Component

<PowerSelectInfinity
    @search={{this.search}}
    @searchField='name'
    @loadMore={{this.loadMore}}
    @selected={{this.selected}}
    @onChange={{fn (mut this.selected)}}
    as |name|
>
    {{name}}
</PowerSelectInfinity>

Your Controller

Paging using page numbers

export default PagingController extends Controller {
    page = 1;

    @action
    search(term) {
        //API call
        let page = get(this, 'page');
        return get(this, 'ajax').request(`names?page=${page}&search=${term}`);
    }

    @action
    loadMore(term) {
        let page = get(this, 'page');
        let newPage = get(this, 'page');
        return get(this, 'ajax').request(`names?page=${newPage}&search=${term}`).then(() => {
            this.page = newPage;
        });
    }
}

Paging using page offset & limit

export default PagingController extends Controller {
    page = 1;

    @action
    search(term) {
        return get(this, 'ajax').request(`names?search=${term}`);
    }

    @action
    async loadMore(term, select) {
        return get(this, 'ajax').request(`names?search=${term}&offset=${get(select, 'resultsCount')}&limit=10`);
    }
}

If you want the power select to open when the input is focused, just pass a list of options via the options parameter.

<PowerSelectInfinity
    @options={{this.options}}
    @search={{this.search}}
    @searchField='name'
    @loadMore={{this.loadMore}}
    @selected={{this.selected}}
    @onChange={{fn (mut this.selected)}}
    as |name|
>
    {{name}}
</PowerSelectInfinity>

If your using a complex objects as the options, you need to tell power-select-infinity what value to display when an option is selected using

<PowerSelectInfinity
    @options={{this.options}}
    @search={{this.search}}
    @searchField='name'
    @loadMore={{this.loadMore}}
    @selected={{this.selected}}
    @onChange={{fn (mut this.selected)}}
    as |user|
>
    {{user.name}}
</PowerSelectInfinity>

In the example above, Im using a user object which has a property of name that I want to display when selected.

There are some options you can pass to https://github.com/html-next/vertical-collection, which is what we use for the occlusion rendering. The three options are estimateHeight, bufferSize, and staticHeight. Read the vertical collection documentation for what they do and how to use them

<PowerSelectInfinity
    @options={{this.options}}
    @estimateHeight={{75}}
    @bufferSize={{10}}
    @staticHeight={{true}}
    @search={{this.search}}
    @searchField='name'
    @loadMore={{this.loadMore}}
    @selected={{this.selected}}
    @onChange={{fn (mut this.selected)}}
    as |name|
>
    {{name}}
</PowerSelectInfinity>

You can also customize the loading component by passing in your own loadingComponent property.

<PowerSelectInfinity
    @options={{this.options}}
    @search={{this.search}}
    @searchField='name'
    @loadMore={{this.loadMore}}
    @selected={{this.selected}}
    @onChange={{fn (mut this.selected)}}
    @loadingComponent='my-loading-component'
    as |name|
>
    {{name}}
</PowerSelectInfinity>

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

ember-power-select-infinity's People

Contributors

bakerac4 avatar gspain-gavant avatar billdami avatar napafundi avatar ember-tomster avatar bmurray-gavant avatar

Stargazers

Antoine Lagadec avatar Alejandro Poladura avatar Anton Sergeenkov avatar  avatar Nelson Páez avatar Jacob Jewell avatar Tony Miller avatar The Game avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

eflexsystems

ember-power-select-infinity's Issues

Fastboot failure

After using power-select-infinity in my project, Im seeing it fails in FastBoot. The interesting thing is that its not failing in my code, its failing in power-select/options.

There was an error running your app in fastboot. More info about the error: 
 TypeError: Cannot read property 'prototype' of undefined
    at Module.callback (/Users/adambaker/Development/gavant/premins-web/glasses/tmp/broccoli_merge_trees-output_path-IjPUFcRR.tmp/assets/addon-tree-output/ember-power-select/components/power-select/options.js:27:1)

Deprecation warning "sendAction("lastReached") but Component#sendAction is deprecated."

Hello guys, I have a static list of 250 items and I just want to show them in the select input, I've tested in the app and after I've scroll to the bottom, I've got this warning message from the console:

DEPRECATION: You called <streetwize-ember@component:vertical-collection::ember460>.sendAction("lastReached") but Component#sendAction is deprecated. Please use closure actions instead. [deprecation id: ember-component.send-action] See https://emberjs.com/deprecations/v3.x#toc_ember-component-send-action for more details.

and the log message doesn't stop to print in the console.

I'm using Ember "v3.8", anyone have same issue?
Also, it is possible to not use the "search" and "loadMore" actions? seems that they are a mandatory actions.

Could not find module `ember-concurrency-ts`

Getting the following error when using this component:

Could not find module `ember-concurrency-ts` imported from `@gavant/ember-power-select-infinity/components/power-select-infinity`

Not using Typescript in the project, so maybe that has something to do with it. But TS isn't listed as a dependency so thinking it should work?

[TODO] Non-typeahead variant

Expose an option that allows for a more traditional power-select, where the search box is inside the options dropdown menu, and we have more control over the selected option template (e.g. for complex html content), instead of just being a plain text typeahead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.