{"_id":"@asadurrehman94/angular2-virtual-scroll","_rev":"1-3ebf100ae4db16c18477a0152edeb855","name":"@asadurrehman94/angular2-virtual-scroll","dist-tags":{"latest":"0.3.2-custom.1"},"versions":{"0.3.2-custom.1":{"name":"@asadurrehman94/angular2-virtual-scroll","version":"0.3.2-custom.1","description":"Angular 2 module for virtual -infinite- list. Supports multi-column","main":"dist/virtual-scroll.js","types":"dist/virtual-scroll.d.ts","scripts":{"cleanup":"rimraf dist","build":"npm run cleanup && npm run ngc","lint":"tslint src/**/*.ts","prepublish":"npm run build","start":"npm run watch","test":"npm test","ngc":"ngc","tslint":"tslint","watch":"ngc -- -w"},"repository":{"type":"git","url":"git+https://github.com/rintoj/angular2-virtual-scroll.git"},"keywords":["virtual scroll","scroll","angular 2"],"author":{"name":"Rinto Jose"},"license":"MIT","bugs":{"url":"https://github.com/rintoj/angular2-virtual-scroll/issues"},"homepage":"https://github.com/rintoj/angular2-virtual-scroll#readme","devDependencies":{"@angular/cli":"^1.3.0","@angular/common":"^4.3.0","@angular/compiler":"^4.3.0","@angular/compiler-cli":"^4.3.0","@angular/core":"^4.3.0","@angular/forms":"^4.3.0","@angular/http":"^4.3.0","@angular/platform-browser":"^4.3.0","@angular/platform-browser-dynamic":"^4.3.0","@angular/router":"^4.3.0","@types/node":"^8.0.14","codelyzer":"^2.0.0","core-js":"^2.4.1","rimraf":"^2.6.1","rxjs":"^5.4.2","tslint":"^5.5.0","typescript":"2.4.1","zone.js":"^0.8.13"},"dependencies":{"@tweenjs/tween.js":"^17.1.0"},"gitHead":"fe53683078fde776844a1508680fb71445d5e8d4","_id":"@asadurrehman94/angular2-virtual-scroll@0.3.2-custom.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.3","_npmUser":{"name":"asadurrehman","email":"asad.rehman@khi.iba.edu.pk"},"dist":{"integrity":"sha512-XAwiheRhujQzw8/hViMjsVmkabxqDD1SQcHNpgGkouME8UFOV2BtW1WSsH21vDYM+Ez+QX6jTDI3NTZjPUYpeA==","shasum":"6fe021e901c4d980305583b631b551995458b997","tarball":"https://registry.npmjs.org/@asadurrehman94/angular2-virtual-scroll/-/angular2-virtual-scroll-0.3.2-custom.1.tgz","fileCount":8,"unpackedSize":58652,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbUJEJCRA9TVsSAnZWagAAG6MP/3WSyTbVHPb4k+v603JV\nwzcDrMsHa6Q7AmacDvp0d55Ezr3ZNEq1NMMcmh176oHbbe6W/7yKC25bkmxp\nXIpIYpGsDx6ESJy2ONoYKPPoigSKKNF7RgwgbqBgbi/U2bt5giz/amm4z31R\n9XP7ufNL56AA/m9CCaj5vSkFfps9HKOPJTNtW9GTySdPGcCG4o6G4+ERd/+s\nm1RqR8cNiZ2JhHenC9T9AbqEU1aTR37dBXe1xvrRc7gbAP7vr2DGdIXJ85fy\nFLIQZH1CkMKulJi0zNK0aW738vsqGwipg+pD6RCcXRCHaIWF0WVMfjjcHn+q\nwkmv2Ve4U5rrJzO5RedvAwBqF6KoZx/lsNOQxhJa4SjBAiCXuQcqjeGTyB7i\nwTShse8VjMpc7wxJ9j0GS5dSCXYQoMiMaCyFagvzdjUIKOmoJZaeI38SJGu1\nV0phqDJljrJxAeg1v24zrKf4DyjieuHkEWs5OxcUymA9EDKXdD9yLle4GvdY\nHIoMY7hdWuPww6bpPTGMRtOcoKAfY/k7O1T+3YM0VFEgyUkrVbqBUXe/5/Qh\nUQFI8IB5vxsQW6VmMhQ3bGbOwMDyVaqdEVsh0CwvRuPqJlqw7XNUFEzCXS9Q\n4OLySUT0AhqB+EP5P0+WGR5gta/MqLdZAMrkJRdVSUHVNA+wEhkJQkvWIJeW\ngLyI\r\n=HGyJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHMqf16RwF6+wUpaugmb5uEu5qeqIykXB6YvSzW9xGfoAiEAoHZ5GGI38Ss6UBeBfr+U1bhxwu5og9mIX0VJ5TJxwgQ="}]},"maintainers":[{"name":"asadurrehman","email":"asad.rehman@khi.iba.edu.pk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/angular2-virtual-scroll_0.3.2-custom.1_1532006665511_0.5824906697281391"},"_hasShrinkwrap":false}},"time":{"created":"2018-07-19T13:24:16.384Z","0.3.2-custom.1":"2018-07-19T13:24:25.864Z","modified":"2022-04-04T15:42:17.722Z"},"maintainers":[{"name":"asadurrehman","email":"asad.rehman@khi.iba.edu.pk"}],"description":"Angular 2 module for virtual -infinite- list. Supports multi-column","homepage":"https://github.com/rintoj/angular2-virtual-scroll#readme","keywords":["virtual scroll","scroll","angular 2"],"repository":{"type":"git","url":"git+https://github.com/rintoj/angular2-virtual-scroll.git"},"author":{"name":"Rinto Jose"},"bugs":{"url":"https://github.com/rintoj/angular2-virtual-scroll/issues"},"license":"MIT","readme":"\n# angular2-virtual-scroll\n\nVirtual Scroll displays a virtual, \"infinite\" list. Supports multi-column.\n\n## About\n\nThis module displays a small subset of records just enough to fill the viewport and uses the same DOM elements as the user scrolls.\nThis method is effective because the number of DOM elements are always constant and tiny irrespective of the size of the list. Thus virtual scroll can display infinitely growing list of items in an efficient way.\n\n* Angular 2 compatible module\n* Supports multi-column\n* Easy to use apis\n* OpenSource and available in GitHub\n\n## New features:\n\n* Added ability to put other elements inside of scroll (Need to wrap list itself in @ContentChild('container'))\n* Added ability to use any parent with scrollbar instead of this element (@Input() parentScroll)\n\n## Demo\n\n[See Demo Here](http://rintoj.github.io/angular2-virtual-scroll)\n\n## Usage\n\n```html\n<virtual-scroll [items]=\"items\" (update)=\"viewPortItems = $event\">\n\n    <list-item *ngFor=\"let item of viewPortItems\" [item]=\"item\">\n    </list-item>\n\n</virtual-scroll>\n```\n\nalternatively\n\n```html\n<virtual-scroll #scroll [items]=\"items\">\n\n    <list-item *ngFor=\"let item of scroll.viewPortItems\" [item]=\"item\">\n    </list-item>\n\n</virtual-scroll>\n```\n\nalternatively\n\n```html\n<div virtualScroll [items]=\"items\" (update)=\"viewPortItems = $event\">\n\n    <list-item *ngFor=\"let item of viewPortItems\" [item]=\"item\">\n    </list-item>\n\n</div>\n```\n\n## Get Started\n\n**Step 1:** Install angular2-virtual-scroll\n\n```sh\nnpm install angular2-virtual-scroll --save\n```\n\n**Step 2:** Import virtual scroll module into your app module\n\n```ts\n....\nimport { VirtualScrollModule } from 'angular2-virtual-scroll';\n\n....\n\n@NgModule({\n    ...\n    imports: [\n        ....\n        VirtualScrollModule\n    ],\n    ....\n})\nexport class AppModule { }\n```\n\n**Step 3:** Wrap virtual-scroll tag around list items;\n\n```ts\n<virtual-scroll [items]=\"items\" (update)=\"viewPortItems = $event\">\n\n    <list-item *ngFor=\"let item of viewPortItems\" [item]=\"item\">\n    </list-item>\n\n</virtual-scroll>\n```\n\nYou must also define width and height for the container and for it's children.\n\n```css\nvirtual-scroll {\n  display: block;\n  width: 350px;\n  height: 200px;\n}\n\nlist-item {\n  display: block;\n  width: 100%;\n  height: 30px;\n}\n\n```\n\n**Step 4:** Create 'list-item' component.\n\n'list-item' must a custom angular2 component, outside of this library. A sample list item is give below or check the [demo app](https://github.com/rintoj/angular2-virtual-scroll/tree/master/demo) for [list-item.component.ts](https://github.com/rintoj/angular2-virtual-scroll/blob/master/demo/src/app/lists/list-item.component.ts).\n\n```ts\nimport { Component, Input } from '@angular/core';\n\nexport interface ListItem {\n    index?: number;\n    name?: string;\n    gender?: string;\n    age?: number;\n    email?: string;\n    phone?: string;\n    address?: string;\n}\n\n@Component({\n    selector: 'list-item',\n    template: `\n        <div class=\"avatar\">{{item.index}}</div>\n        <div class=\"item-content\">\n            <div class=\"name\">{{item.name}}</div>\n            <div>\n                <span class=\"badge\">{{item.age}} / {{item.gender}}</span>\n                <span>{{item.email}} | {{item.phone}}</span>\n            </div>\n            <div>{{item.address}}</div>\n        </div>\n    `,\n    styleUrls: ['./list-item.scss']\n})\nexport class ListItemComponent {\n    @Input()\n    item: ListItem;\n}\n```\n\nChild component is not a necessity if your item is simple enough. See below.\n\n```html\n<virtual-scroll [items]=\"items\" (update)=\"viewPortItems = $event\">\n    <div *ngFor=\"let item of viewPortItems\">{{item?.name}}</div>\n</virtual-scroll>\n```\n\n## API\n\n| Attribute      | Type   | Description\n|----------------|--------|------------\n| items          | any[]  | The data that builds the templates within the virtual scroll. This is the same data that you'd pass to ngFor. It's important to note that when this data has changed, then the entire virtual scroll is refreshed.\n| childWidth     | number | The minimum width of the item template's cell. This dimension is used to help determine how many cells should be created when initialized, and to help calculate the height of the scrollable area. Note that the actual rendered size of the first cell is used by default if not specified.\n| childHeight    | number | The minimum height of the item template's cell. This dimension is used to help determine how many cells should be created when initialized, and to help calculate the height of the scrollable area. Note that the actual rendered size of the first cell is used by default if not specified.\n| bufferAmount   | number | The the number of elements to be rendered outside of the current container's viewport. Useful when not all elements are the same dimensions.\n| scrollAnimationTime | number | The time in milliseconds for the scroll animation to run for. Default value is 1500\n| parentScroll   | Element / Window | Element (or window), which will have scrollbar. This element must be one of the parents of virtual-scroll\n| update         | Event  | This event is fired every time `start` or `end` index change and emits list of items from `start` to `end`. The list emitted by this event must be used with `*ngFor` to render the actual list of items within `<virtual-scroll>`\n| change         | Event  | This event is fired every time `start` or `end` index change and emits `ChangeEvent` which of format: `{ start: number, end: number }`\n\n## Getting view port items without events\n\nIf you are using AOT compilation (hope you do it) then in classic usage (with listening to `update` event) it is required to create field `viewPortItems` in your component.\nThere is a way how to avoid it.\n\n```html\n<virtual-scroll #scroll [items]=\"items\">\n\n    <list-item *ngFor=\"let item of scroll.viewPortItems\" [item]=\"item\">\n    </list-item>\n\n</virtual-scroll>\n```\n\n## Additional elements in scroll\n\nIf inside of content of virtual scroll element you want to show also additional elements except list itself (e.g. search field), you need to specify block with list using id \"container\".\n\n```html\n<virtual-scroll [items]=\"items\"\n    (update)=\"viewPortItems = $event\">\n    <input type=\"search\">\n    <div #container>\n        <list-item *ngFor=\"let item of viewPortItems\" [item]=\"item\">\n        </list-item>\n    </div>\n</virtual-scroll>\n```\n\n## Use scrollbar of parent block\n\nIf you want to use scrollbar of parent block, instead of scrolling block, set `parentScroll`.\n\n```html\n<div #scrollingBlock>\n    <virtual-scroll [items]=\"items\"\n        [parentScroll]=\"scrollingBlock.nativeElement\"\n        (update)=\"viewPortItems = $event\">\n        <input type=\"search\">\n        <div #container>\n            <list-item *ngFor=\"let item of viewPortItems\" [item]=\"item\">\n            </list-item>\n        </div>\n    </virtual-scroll>\n</div>\n```\n\n## Use scrollbar of window\n\nIf you want to use scrollbar of window, instead of scrolling block, set `parentScroll`.\n\n```html\n<virtual-scroll\n    #scroll\n    [items]=\"items\"\n    [parentScroll]=\"scroll.window\">\n    <input type=\"search\">\n    <div #container>\n        <list-item *ngFor=\"let item of scroll.viewPortItems\" [item]=\"item\">\n        </list-item>\n    </div>\n</virtual-scroll>\n```\n\n## Items with variable size\n\nItems must have fixed height and width for this module to work perfectly. However if your list happen to have items with variable width and height, set inputs `childWidth` and `childHeight` to the smallest possible values to make this work.\n\n```html\n<virtual-scroll [items]=\"items\"\n    [childWidth]=\"80\"\n    [childHeight]=\"30\"\n    (update)=\"viewPortItems = $event\">\n\n    <list-item *ngFor=\"let item of viewPortItems\" [item]=\"item\">\n    </list-item>\n\n</virtual-scroll>\n```\n\n## Loading in chunk\n\nThe event `end` is fired every time scroll reaches at the end of the list. You could use this to load more items at the end of the scroll. See below.\n\n```ts\n\nimport { ChangeEvent } from '@angular2-virtual-scroll';\n...\n\n@Component({\n    selector: 'list-with-api',\n    template: `\n        <virtual-scroll [items]=\"buffer\" (update)=\"scrollItems = $event\"\n            (end)=\"fetchMore($event)\">\n\n            <list-item *ngFor=\"let item of scrollItems\" [item]=\"item\"> </list-item>\n            <div *ngIf=\"loading\" class=\"loader\">Loading...</div>\n\n        </virtual-scroll>\n    `\n})\nexport class ListWithApiComponent implements OnChanges {\n\n    @Input()\n    items: ListItem[];\n\n    protected buffer: ListItem[] = [];\n    protected loading: boolean;\n\n    protected fetchMore(event: ChangeEvent) {\n        if (event.end !== this.buffer.length) return;\n        this.loading = true;\n        this.fetchNextChunk(this.buffer.length, 10).then(chunk => {\n            this.buffer = this.buffer.concat(chunk);\n            this.loading = false;\n        }, () => this.loading = false);\n    }\n\n    protected fetchNextChunk(skip: number, limit: number): Promise<ListItem[]> {\n        return new Promise((resolve, reject) => {\n            ....\n        });\n    }\n}\n```\n\n## If container size change\n\nIf virtual scroll is used within a dropdown or collapsible menu, virtual scroll needs to know when the container size change. Use `refresh()` function after container is resized (include time for animation as well).\n\n```ts\nimport { Component, ViewChild } from '@angular/core';\nimport { VirtualScrollComponent } from 'angular2-virtual-scroll';\n\n@Component({\n    selector: 'rj-list',\n    template: `\n        <virtual-scroll [items]=\"items\" (update)=\"scrollList = $event\">\n            <div *ngFor=\"let item of scrollList; let i = index\"> {{i}}: {{item}} </div>\n        </virtual-scroll>\n    `\n})\nexport class ListComponent {\n\n    protected items = ['Item1', 'Item2', 'Item3'];\n\n    @ViewChild(VirtualScrollComponent)\n    private virtualScroll: VirtualScrollComponent;\n\n    // call this function after resize + animation end\n    afterResize() {\n        this.virtualScroll.refresh();\n    }\n}\n```\n\n## Focus on an item\n\nYou could use `scrollInto(item)` api to scroll into an item in the list. See below:\n\n```ts\nimport { Component, ViewChild } from '@angular/core';\nimport { VirtualScrollComponent } from 'angular2-virtual-scroll';\n\n@Component({\n    selector: 'rj-list',\n    template: `\n        <virtual-scroll [items]=\"items\" (update)=\"scrollList = $event\">\n            <div *ngFor=\"let item of scrollList; let i = index\"> {{i}}: {{item}} </div>\n        </virtual-scroll>\n    `\n})\nexport class ListComponent {\n\n    protected items = ['Item1', 'Item2', 'Item3'];\n\n    @ViewChild(VirtualScrollComponent)\n    private virtualScroll: VirtualScrollComponent;\n\n    // call this function whenever you have to focus on second item\n    focusOnAnItem() {\n        this.virtualScroll.items = this.items;\n        this.virtualScroll.scrollInto(items[1]);\n    }\n}\n```\n\n## Sorting Items\n\nAlways be sure to send an immutable copy of items to virtual scroll to avoid unintended behavior. You need to be careful when doing non-immutable operations such as sorting:\n\n```ts\nsort() {\n  this.items = [].concat(this.items || []).sort()\n}\n```\n\nThis will be deprecated once [Resize Observer](https://wicg.github.io/ResizeObserver/) is fully implemented.\n\n## Contributing\nContributions are very welcome! Just send a pull request. Feel free to contact me or checkout my [GitHub](https://github.com/rintoj) page.\n\n## Author\n\n* **Rinto Jose** (rintoj)\n* **Pavel Kukushkin** (kykint)\n\n### Hope this module is helpful to you. Please make sure to checkout my other [projects](https://github.com/rintoj) and [articles](https://medium.com/@rintoj). Enjoy coding!\n\nFollow me:\n  [GitHub](https://github.com/rintoj)\n| [Facebook](https://www.facebook.com/rinto.jose)\n| [Twitter](https://twitter.com/rintoj)\n| [Google+](https://plus.google.com/+RintoJoseMankudy)\n| [Youtube](https://youtube.com/+RintoJoseMankudy)\n\n## Versions\n[Check CHANGELOG](https://github.com/rintoj/angular2-virtual-scroll/blob/master/CHANGELOG.md)\n\n## License\n```\nThe MIT License (MIT)\n\nCopyright (c) 2016 Rinto Jose (rintoj)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","readmeFilename":"README.md"}