{"id":15141952,"url":"https://github.com/peterstaev/nativescript-grid-view","last_synced_at":"2025-10-23T19:30:58.987Z","repository":{"id":57308544,"uuid":"42646739","full_name":"PeterStaev/NativeScript-Grid-View","owner":"PeterStaev","description":"A NatvieScript GridView widget.","archived":false,"fork":false,"pushed_at":"2020-05-14T07:15:21.000Z","size":6960,"stargazers_count":49,"open_issues_count":3,"forks_count":28,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-30T20:30:32.717Z","etag":null,"topics":["android","grid","gridview","ios","nativescript","uicollectionview"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PeterStaev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-17T09:14:48.000Z","updated_at":"2024-05-30T15:50:55.000Z","dependencies_parsed_at":"2022-08-28T23:03:34.519Z","dependency_job_id":null,"html_url":"https://github.com/PeterStaev/NativeScript-Grid-View","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterStaev%2FNativeScript-Grid-View","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterStaev%2FNativeScript-Grid-View/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterStaev%2FNativeScript-Grid-View/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterStaev%2FNativeScript-Grid-View/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeterStaev","download_url":"https://codeload.github.com/PeterStaev/NativeScript-Grid-View/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237877021,"owners_count":19380344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","grid","gridview","ios","nativescript","uicollectionview"],"created_at":"2024-09-26T09:21:01.937Z","updated_at":"2025-10-23T19:30:58.308Z","avatar_url":"https://github.com/PeterStaev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"**This repo only supports NativeScript pre-6.0. The latest version of the plugin supporting NS 6+ is availble as part of [ProPlugins](https://proplugins.org).**\n# NativeScript GridView widget\n[![Build Status](https://travis-ci.org/PeterStaev/NativeScript-Grid-View.svg?branch=master)](https://travis-ci.org/PeterStaev/NativeScript-Grid-View)\n[![npm downloads](https://img.shields.io/npm/dm/nativescript-grid-view.svg)](https://www.npmjs.com/package/nativescript-grid-view)\n[![npm downloads](https://img.shields.io/npm/dt/nativescript-grid-view.svg)](https://www.npmjs.com/package/nativescript-grid-view)\n[![npm](https://img.shields.io/npm/v/nativescript-grid-view.svg)](https://www.npmjs.com/package/nativescript-grid-view)\n\nA NativeScript GridView widget. The GridView displays data in separate cells, each cell representing one data item. For iOS wraps up [UICollectionView](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/) and for Android wraps up [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html)\n\n## Screenshot\n![Screenshot of Android](https://raw.githubusercontent.com/PeterStaev/NativeScript-Grid-View/master/docs/screenshot.png)\n\n## Installation\nRun the following command from the root of your project:\n\n`tns plugin add nativescript-grid-view`\n\nThis command automatically installs the necessary files, as well as stores nativescript-grid-view as a dependency in your project's package.json file.\n\n## Configuration\nThere is no additional configuration needed!\n\n## API\n\n### Events\n* **itemLoading**  \nTriggered when generating an item in the GridView. \n\n* **itemTap**  \nTriggered when the user taps on an item in the GridView. \n\n* **loadMoreItems**  \nTriggered when the generated items reached the end of the items property.\n\n* **scroll**  \nTriggered when the GrdiView is scrolled by the user. from the `args` you can get the new horizonta/vertical offset.\n\n### Static Properties\n* **itemLoadingEvent** - *String*  \nString value used when hooking to itemLoadingEvent event.\n\n* **itemTapEvent** - *String*  \nString value used when hooking to itemTapEvent event.\n\n* **loadMoreItemsEvent** - *String*  \nString value used when hooking to itemTapEvent event.\n\n* **scrollEvent** - *String*  \nString value used when hooking to scroll event.\n\n### Instance Properties\n* **ios** - *[UICollectionView](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/)*  \nGets the native iOS view that represents the user interface for this component. Valid only when running on iOS.\n\n* **android** - *[android.support.v7.widget.RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html)*  \nGets the native android widget that represents the user interface for this component. Valid only when running on Android OS.\n\n* **items** - *Array | ItemsSource*  \nGets or sets the items collection of the GridView. The items property can be set to an array or an object defining length and getItem(index) method.\n\n* **itemTemplate** - *String*  \nGets or sets the item template of the GridView.\n\n* **rowHeight** - *PercentLength*  \nGets or sets the height for every row in the GridView.\n\n* **colWidth** - *PercentLength*  \nGets or sets the width for every column in the GridView.\n\n### Instance Methods\n* **refresh()**  \nForces the GridView to reload all its items.\n\n* **scrollToIndex(index: number, animated: boolean = true)**  \nScrolls the GridView to the item with the given index. This can be either animated or not. Defaults to animated.\n\n## Usage\nYou need to add `xmlns:gv=\"nativescript-grid-view\"` to your page tag, and then simply use `\u003cgv:GridView/\u003e` in order to add the widget to your page. Use `\u003cgv:Gridview.itemTemplate/\u003e` to specify the template for each cell:\n\n```xml\n\u003c!-- test-page.xml --\u003e\n\u003cPage xmlns=\"http://schemas.nativescript.org/tns.xsd\" xmlns:gv=\"nativescript-grid-view\" loaded=\"pageLoaded\"\u003e\n  \u003cGridLayout\u003e\n    \u003cgv:GridView items=\"{{ items }}\" colWidth=\"24%\" rowHeight=\"15%\" padding=\"5\" itemTap=\"gridViewItemTap\" itemLoading=\"gridViewItemLoading\" loadMoreItems=\"gridViewLoadMoreItems\"\u003e\n      \u003cgv:GridView.itemTemplate\u003e\n        \u003cGridLayout backgroundColor=\"#33ffff\" style=\"margin: 5\"\u003e\n          \u003cLabel text=\"{{ value }}\" verticalAlignment=\"center\"/\u003e\n        \u003c/GridLayout\u003e\n      \u003c/gv:GridView.itemTemplate\u003e\n    \u003c/gv:GridView\u003e\n  \u003c/GridLayout\u003e\n\u003c/Page\u003e\n```\n\n```ts\n// test-page.ts\nimport { EventData, Observable } from \"data/observable\";\nimport { ObservableArray } from \"data/observable-array\";\nimport { Page } from \"ui/page\";\n\nimport { GridItemEventData } from \"nativescript-grid-view\";\n\nlet viewModel: Observable;\n\nexport function pageLoaded(args: EventData) {\n    const page = args.object as Page;\n    const items = new ObservableArray();\n\n    for (let loop = 0; loop \u003c 200; loop++) {\n        items.push({ value: \"test \" + loop.toString() });\n    }\n    viewModel = new Observable();\n    viewModel.set(\"items\", items);\n\n    page.bindingContext = viewModel;\n}\n\nexport function gridViewItemTap(args: GridItemEventData) {\n    console.log(\"tap index \" + args.index.toString());\n}\n\nexport function gridViewItemLoading(args: GridItemEventData) {\n    console.log(\"item loading \" + args.index.toString());\n}\n\nexport function gridViewLoadMoreItems(args: EventData) {\n    console.log(\"load more items\");\n}\n```\n\nYou can also have multiple templates the same way you add them in the builtin `ListView` control:\n```xml\n\u003cgv:GridView id=\"gv\" row=\"0\" class=\"{{ cssClass }}\" items=\"{{ items }}\" \n                colWidth=\"{{ colWidth }}\" rowHeight=\"{{ rowHeight }}\" itemTemplateSelector=\"templateSelector\"\n                itemTap=\"gridViewItemTap\" itemLoading=\"gridViewItemLoading\" loadMoreItems=\"gridViewLoadMoreItems\"\u003e\n    \u003cgv:GridView.itemTemplates\u003e\n        \u003ctemplate key=\"odd\"\u003e\n            \u003cGridLayout backgroundColor=\"#33ffff\" style=\"margin: 10 10 0 0\"\u003e\n                \u003cLabel text=\"{{ value }}\" verticalAlignment=\"center\"/\u003e\n            \u003c/GridLayout\u003e\n        \u003c/template\u003e\n\n        \u003ctemplate key=\"even\"\u003e\n            \u003cGridLayout backgroundColor=\"#33ffff\" rows=\"auto, auto\" style=\"margin: 10 10 0 0\"\u003e\n                \u003cLabel row=\"0\" text=\"{{ value }}\" verticalAlignment=\"center\"/\u003e\n                \u003cLabel row=\"1\" text=\"{{ value }}\" verticalAlignment=\"center\"/\u003e\n            \u003c/GridLayout\u003e\n        \u003c/template\u003e\n    \u003c/gv:GridView.itemTemplates\u003e\n\u003c/gv:GridView\u003e\n```\n```ts\nexport function templateSelector(item: any, index: number, items: any) {\n    return index % 2 === 0 ? \"even\" : \"odd\";\n}\n```\n\n## Usage in Angular\n\nImport `GridViewModule` in your `NgModule`:\n\n```typescript\nimport { GridViewModule } from 'nativescript-grid-view/angular';\n\n@NgModule({\n    //......\n    imports: [\n        //......\n        GridViewModule,\n        //......\n    ],\n    //......\n})\n```\n\n#### Example Usage\n```ts\n// app.module.ts\nimport { GridViewModule } from \"nativescript-grid-view/angular\";\n\n@NgModule({\n    bootstrap: [\n        AppComponent\n    ],\n    imports: [\n        NativeScriptModule,\n        AppRoutingModule,\n        GridViewModule,\n    ],\n    declarations: [\n        AppComponent,\n        ItemsComponent,\n        ItemDetailComponent\n    ],\n    providers: [\n        ItemService\n    ],\n    schemas: [\n        NO_ERRORS_SCHEMA\n    ]\n})\nexport class AppModule { }\n```\n\n```html\n\u003c!-- my.component.html --\u003e\n\u003cGridLayout class=\"page\"\u003e\n  \u003cGridView [items]=\"items\" colWidth=\"30%\" rowHeight=\"100\"\u003e\n    \u003cng-template let-item=\"item\" let-odd=\"odd\"\u003e\n      \u003cStackLayout margin=\"10\" [nsRouterLink]=\"['/item', item.id]\" borderColor=\"blue\" borderWidth=\"2\" borderRadius=\"5\" verticalAlignment=\"stretch\" class=\"list-group-item\" [class.odd]=\"odd\"\u003e\n        \u003cLabel verticalAlignment=\"center\" [text]=\"item.name\" class=\"list-group-item-text\" textWrap=\"true\"\u003e\u003c/Label\u003e\n      \u003c/StackLayout\u003e\n    \u003c/ng-template\u003e\n  \u003c/GridView\u003e\n\u003c/GridLayout\u003e\n```\n\nIf you want to use multiple item templates, you can do that very similarly to how you do it for the builtin `ListView` control.\n```html\n\u003cGridView row=\"1\" [items]=\"items\" colWidth=\"33%\" rowHeight=\"100\" [itemTemplateSelector]=\"templateSelector\"\u003e\n    \u003cng-template nsTemplateKey=\"Defender\" let-item=\"item\" let-odd=\"odd\"\u003e\n        \u003cStackLayout [nsRouterLink]=\"['/item', item.id]\" borderColor=\"blue\" borderWidth=\"2\" borderRadius=\"5\" verticalAlignment=\"stretch\" class=\"list-group-item\" [class.odd]=\"odd\"\u003e\n        \u003cLabel verticalAlignment=\"center\" [text]=\"item.name\" class=\"list-group-item-text\" textWrap=\"true\"\u003e\u003c/Label\u003e\n        \u003c/StackLayout\u003e\n    \u003c/ng-template\u003e\n\n    \u003cng-template nsTemplateKey=\"Goalkeeper\" let-item=\"item\" let-odd=\"odd\"\u003e\n        \u003cStackLayout [nsRouterLink]=\"['/item', item.id]\" borderColor=\"black\" borderWidth=\"2\" borderRadius=\"5\" verticalAlignment=\"stretch\" class=\"list-group-item\" [class.odd]=\"odd\"\u003e\n        \u003cLabel verticalAlignment=\"center\" [text]=\"item.name\" class=\"list-group-item-text\" textWrap=\"true\"\u003e\u003c/Label\u003e\n        \u003c/StackLayout\u003e\n    \u003c/ng-template\u003e\n\n    \u003cng-template nsTemplateKey=\"Midfielder\" let-item=\"item\" let-odd=\"odd\"\u003e\n        \u003cStackLayout [nsRouterLink]=\"['/item', item.id]\" borderColor=\"yellow\" borderWidth=\"2\" borderRadius=\"5\" verticalAlignment=\"stretch\" class=\"list-group-item\" [class.odd]=\"odd\"\u003e\n        \u003cLabel verticalAlignment=\"center\" [text]=\"item.name\" class=\"list-group-item-text\" textWrap=\"true\"\u003e\u003c/Label\u003e\n        \u003c/StackLayout\u003e\n    \u003c/ng-template\u003e\n\n    \u003cng-template nsTemplateKey=\"Forward\" let-item=\"item\" let-odd=\"odd\"\u003e\n        \u003cStackLayout [nsRouterLink]=\"['/item', item.id]\" borderColor=\"red\" borderWidth=\"2\" borderRadius=\"5\" verticalAlignment=\"stretch\" class=\"list-group-item\" [class.odd]=\"odd\"\u003e\n        \u003cLabel verticalAlignment=\"center\" [text]=\"item.name\" class=\"list-group-item-text\" textWrap=\"true\"\u003e\u003c/Label\u003e\n        \u003c/StackLayout\u003e\n    \u003c/ng-template\u003e\n\u003c/GridView\u003e\n```\n\n## Demos\nThis repository includes both Angular and plain NativeScript demos. In order to run those execute the following in your shell:\n```shell\n$ git clone https://github.com/peterstaev/nativescript-grid-view\n$ cd nativescript-grid-view\n$ npm install\n$ npm run demo-ios\n```\nThis will run the plain NativeScript demo project on iOS. If you want to run it on Android simply use the `-android` instead of the `-ios` sufix. \n\nIf you want to run the Angular demo simply use the `demo-ng-` prefix instead of `demo-`. \n\n## Donate\n[![Donate](https://img.shields.io/badge/paypal-donate-brightgreen.svg)](https://bit.ly/2AS9QKB)\n\n`bitcoin:14fjysmpwLvSsAskvLASw6ek5XfhTzskHC`\n\n![Donate](https://www.tangrainc.com/qr.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterstaev%2Fnativescript-grid-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterstaev%2Fnativescript-grid-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterstaev%2Fnativescript-grid-view/lists"}