A NativeScript GridView widget. The GridView displays data in separate cells, each cell representing one data item. For iOS wraps up UICollectionView and for Android wraps up RecyclerView
Screenshot
Installation
Run the following command from the root of your project:
tns plugin add nativescript-grid-view
This command automatically installs the necessary files, as well as stores nativescript-grid-view as a dependency in your project's package.json file.
Configuration
There is no additional configuration needed!
API
Events
itemLoading
Triggered when generating an item in the GridView.
itemTap
Triggered when the user taps on an item in the GridView.
loadMoreItems
Triggered when the generated items reached the end of the items property.
scroll
Triggered when the GrdiView is scrolled by the user. from the args you can get the new horizonta/vertical offset.
Static Properties
itemLoadingEvent - String
String value used when hooking to itemLoadingEvent event.
itemTapEvent - String
String value used when hooking to itemTapEvent event.
loadMoreItemsEvent - String
String value used when hooking to itemTapEvent event.
scrollEvent - String
String value used when hooking to scroll event.
Instance Properties
ios - UICollectionView
Gets the native iOS view that represents the user interface for this component. Valid only when running on iOS.
android - android.support.v7.widget.RecyclerView
Gets the native android widget that represents the user interface for this component. Valid only when running on Android OS.
items - Array | ItemsSource
Gets 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.
itemTemplate - String
Gets or sets the item template of the GridView.
rowHeight - PercentLength
Gets or sets the height for every row in the GridView.
colWidth - PercentLength
Gets or sets the width for every column in the GridView.
Instance Methods
refresh()
Forces the GridView to reload all its items.
scrollToIndex(index: number, animated: boolean = true)
Scrolls the GridView to the item with the given index. This can be either animated or not. Defaults to animated.
Usage
You need to add xmlns:gv="nativescript-grid-view" to your page tag, and then simply use <gv:GridView/> in order to add the widget to your page. Use <gv:Gridview.itemTemplate/> to specify the template for each cell: