Skip to content

Commit 7cfdbf4

Browse files
committed
add itemTemplates examples
1 parent 3cab59e commit 7cfdbf4

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,33 @@ export function gridViewLoadMoreItems(args: EventData) {
121121
}
122122
```
123123

124+
You can also have multiple templates the same way you add them in the builtin `ListView` control:
125+
```xml
126+
<gv:GridView id="gv" row="0" class="{{ cssClass }}" items="{{ items }}"
127+
colWidth="{{ colWidth }}" rowHeight="{{ rowHeight }}" itemTemplateSelector="templateSelector"
128+
itemTap="gridViewItemTap" itemLoading="gridViewItemLoading" loadMoreItems="gridViewLoadMoreItems">
129+
<gv:GridView.itemTemplates>
130+
<template key="odd">
131+
<GridLayout backgroundColor="#33ffff" style="margin: 10 10 0 0">
132+
<Label text="{{ value }}" verticalAlignment="center"/>
133+
</GridLayout>
134+
</template>
135+
136+
<template key="even">
137+
<GridLayout backgroundColor="#33ffff" rows="auto, auto" style="margin: 10 10 0 0">
138+
<Label row="0" text="{{ value }}" verticalAlignment="center"/>
139+
<Label row="1" text="{{ value }}" verticalAlignment="center"/>
140+
</GridLayout>
141+
</template>
142+
</gv:GridView.itemTemplates>
143+
</gv:GridView>
144+
```
145+
```ts
146+
export function templateSelector(item: any, index: number, items: any) {
147+
return index % 2 === 0 ? "even" : "odd";
148+
}
149+
```
150+
124151
## Usage in Angular
125152

126153
Import `GridViewModule` in your `NgModule`:
@@ -181,6 +208,35 @@ export class AppModule { }
181208
</GridLayout>
182209
```
183210

211+
If you want to use multiple item templates, you can do that very similarly to how you do it for the builtin `ListView` control. The only difference is that due to current limitations instead of using the `nsTemplateKey` directive you need to use the `gvTemplateKey` directive that comes from the GridView. (In a future version, once the framework allows it this will be changed and you will be able to use the same directive for the `GridView` as well)
212+
```html
213+
<GridView row="1" [items]="items" colWidth="33%" rowHeight="100" [itemTemplateSelector]="templateSelector">
214+
<ng-template gvTemplateKey="Defender" let-item="item" let-odd="odd">
215+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="blue" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
216+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
217+
</StackLayout>
218+
</ng-template>
219+
220+
<ng-template gvTemplateKey="Goalkeeper" let-item="item" let-odd="odd">
221+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="black" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
222+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
223+
</StackLayout>
224+
</ng-template>
225+
226+
<ng-template gvTemplateKey="Midfielder" let-item="item" let-odd="odd">
227+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="yellow" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
228+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
229+
</StackLayout>
230+
</ng-template>
231+
232+
<ng-template gvTemplateKey="Forward" let-item="item" let-odd="odd">
233+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="red" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
234+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
235+
</StackLayout>
236+
</ng-template>
237+
</GridView>
238+
```
239+
184240
## Working with Webpack+Uglify
185241
In case you are uing webpack and also are minifying/uglifying your code, there are some specific names that should be excluded from the uglification for the widget to work properly. The GridView widget exports those and you need to add them to the mangle exclude option of the uglifyjs plugin in the `webpack.common.js` file:
186242
```js

0 commit comments

Comments
 (0)