Git Product home page Git Product logo

ng-infinite-iscroll's Introduction

A fast scroller directive for very large sets of data.

Scrolling large sets using AngularJS that actually work on mobile devices can be quite a challenge! What this directive allows you to do is to create a scroll view over a large set of data by only requesting a window of the data that is actually visible.

This directive only adds a minimal amount of elements to the DOM so it works well on mobile devices.

This directive here is based on iScroll which was slighly modified. iScroll is built into this directive due to the changes that have been made to it.

Usage

You can use it as follows in your view:

 <infinite-list 
        request-data="getData" 
        row-template="'<p>The item: {{item}}</p>'" />

Now in your controller you need a function that fetches the data:

 $scope.getData = function(offset, size) {
    var def = $q.defer();
    // This is the actual data format we need to return..
    var data = {
      limits {
        start : offset,
        end   : offset + size,
        total : 10000
      },
      items : []
    };
    for(var i = offset; i < Math.min(offset + size, 10000); i++) {
          data.items.push('Element: ' + i);
    }
    def.resolve(data);
    return def.promise;
  };

You can also use row-template-url if your template is stored in a file somewhere. You can also watch a variable, which will trigger a refresh. You can pass in iScroll options using the options attribute. For example:

<infinite-list request-data="getSetData" 
               row-template="'<p>[{{item}}]</p>'" 
               options="iscrollOptions" 
               refresh="'set.size, set.order'"  />

Note! Your template should have a fixed height! Otherwise the scroller will not work! Note! Your template will be called with scope.item === undefined in case the item is not yet retrieved

Now you might have a scenario where you would like to show data that is grouped, and want to have a Grouped By header introduced in between the normal rows. You can accomplish this by setting the header template as well. For example:

<infinite-list request-data="getGroupData" header-template="'<H1>{{item}}!</H1>'" row-template="'<p>[{{item}}]</p>'" />

 $scope.getData = function(offset, size) {
    var def = $q.defer();
    // This is the actual data format we need to return..
    var data = {
      limits {
        start : offset,
        end   : offset + size,
        total : 10000
      },
      groupBy : [
          { item : 'Group 1', offset : 0 },
          { item : 'Group 2', offset : 10 },
          { item : 'Another group', offset : 25 },
          { item : 'Groups etc..', offset : 100 },
      ],
      items : []
    };
    for(var i = offset; i < Math.min(offset + size, 10000); i++) {
          data.items.push('Element: ' + i);
    }
    def.resolve(data);
    return def.promise;
  };

This will result in a Header row being rendered at the given offset position. So at offset 0 your header template would be bound to item : 'Group 1'

Demo

http://pokowaka.github.io/ng-infinite-iscroll/

Dependencies

  • required:
  • optional [TODO]

See bower.json and index.html in the gh-pages branch for a full list / more details

Install

  1. download the files
    1. Bower
      1. add "ng-infinite-iscroll": "latest" to your bower.json file then run bower install OR run bower install ng-infinite-iscroll
  2. include the files in your app
    1. nite-iscroll.min.js
    2. nite-iscroll.less OR nite-iscroll.min.css OR nite-iscroll.css
  3. include the module in angular (i.e. in app.js) - pokowaka.ng-infinite-iscroll

See the gh-pages branch, files bower.json and index.html for a full example.

Documentation

See the nite-iscroll.js file top comments for usage examples and documentation https://github.com/pokowaka/ng-infinite-iscroll/blob/master/nite-iscroll.js

Development

  1. git checkout gh-pages
    1. run npm install && bower install
    2. write your code then run grunt
    3. git commit your changes
  2. copy over core files (.js and .css/.less for directives) to master branch
    1. git checkout master
    2. git checkout gh-pages nite-iscroll.js nite-iscroll.min.js nite-iscroll.less nite-iscroll.css nite-iscroll.min.css
  3. update README, CHANGELOG, bower.json, and do any other final polishing to prepare for publishing
    1. git commit changes
    2. git tag with the version number, i.e. git tag v1.0.0
  4. create github repo and push
    1. [if remote does not already exist or is incorrect] git remote add origin [github url]
    2. git push origin master --tags (want to push master branch first so it is the default on github)
    3. git checkout gh-pages
    4. git push origin gh-pages
  5. (optional) register bower component
    1. bower register ng-infinite-iscroll [git repo url]

ng-infinite-iscroll's People

Contributors

pokowaka avatar

Stargazers

 avatar Jack Chan avatar Benjamin Tse avatar  avatar Eugene Yakubovich avatar

Watchers

 avatar

ng-infinite-iscroll's Issues

Header caching can be improved.

Right now we have to re-compile the header template. It should be possible to just reuse pre-created header

  • elements that are hidden in the dom.

  • We have ghost elements when all rows fit in scroll component

    If all the elements fit within the scroll window we see elements that are getting rendered that should not be rendered.

    Just load the sample page and you will see. Oddly enough if you change the set size (large set button), scroll half way in and change back to small, it self corrects.

    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.