You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/ui/list-view.md
+151-5Lines changed: 151 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,19 @@
1
1
---
2
2
title: ListView
3
-
description: UI component for rendering large lists using view recycling.
3
+
description: UI component for rendering large lists using view recycling, with optional sticky headers, sectioned data, and an integrated search bar.
4
4
contributors:
5
5
- rigor789
6
6
- Ombuweb
7
+
- NathanWalker
7
8
---
8
9
9
-
`<ListView>` is a UI component that renders items in a vertically scrolling list, the template for the items can be defined via `itemTemplate` (or multiple templates via `itemTemplates`- more on that below). The ListView only renders the visible items, as the user scrolls, new items render by reusing a no-longer-visible item's view—this is usually referred to as view-recycling.
10
+
`<ListView>` is a UI component that renders items in a vertically scrolling list. The template for the items can be defined via `itemTemplate` (or multiple templates via `itemTemplates`— more on that below). The ListView only renders the visible items; as the user scrolls, new items render by reusing a no-longer-visible item's view — this is usually referred to as view-recycling.
10
11
11
-
::: tip
12
+
Newer versions of `ListView` (v9+) can also render **sectioned data** (for example, A–Z lists) with **sticky headers** and an **optional search bar** that can auto-hide on iOS.
12
13
13
-
For additional features and improved performance in certain scenarios, consider using an alternative implementation like the
14
+
::: tip
15
+
You can also explore
14
16
[CollectionView](https://github.com/nativescript-community/ui-collectionview) from the community.
15
-
16
17
:::
17
18
18
19
<DeviceFrametype="ios">
@@ -78,6 +79,72 @@ Individual items can be rendered using a different template. For example, let's
78
79
</Tab>
79
80
</Tabs>
80
81
82
+
### Sectioned ListView with sticky headers and search
83
+
84
+
Starting with v9, ListView can render sectioned data with sticky headers and an optional search bar. This is useful for contact lists, country lists, or any data grouped by a key.
// apply filtering to your backing data if desired
139
+
})
140
+
```
141
+
142
+
Notes:
143
+
144
+
-`searchAutoHide` is currently iOS-only (it will auto-hide the search on scroll).
145
+
-`stickyHeaderTemplate` accepts the same binding context as the section (`title`, etc.).
146
+
- Make sure each section’s `items` array is present; empty / null sections may not render as expected.
147
+
81
148
## Props
82
149
83
150
### items
@@ -128,6 +195,71 @@ Gets or sets the available itemTemplates.
128
195
129
196
See [KeyedTemplate](/api/interface/KeyedTemplate).
130
197
198
+
### sectioned
199
+
200
+
```ts
201
+
sectioned: boolean
202
+
```
203
+
204
+
Enables sectioned data rendering on the `ListView`. When `true`, the ListView expects the `items` source to be an **array of sections** where each section has a `title` (or similar field) and an `items` array:
205
+
206
+
```ts
207
+
{
208
+
title: string;
209
+
items: any[];
210
+
}
211
+
```
212
+
213
+
This allows the ListView to render grouped lists with headers.
214
+
215
+
### stickyHeader
216
+
217
+
```ts
218
+
stickyHeader: boolean
219
+
```
220
+
221
+
Enables sticky (pinned) headers while scrolling sectioned data. When enabled, the current section header stays at the top of the list until the next section header pushes it away.
222
+
223
+
### stickyHeaderTemplate
224
+
225
+
```ts
226
+
stickyHeaderTemplate: string|KeyedTemplate
227
+
```
228
+
229
+
Gets or sets the template used to render a section header when sticky headers are enabled. This accepts bindings from the current section (for example: `{{ title }}`).
230
+
231
+
### stickyHeaderHeight
232
+
233
+
```ts
234
+
stickyHeaderHeight: number
235
+
```
236
+
237
+
Explicit height for the sticky header. Providing this can improve measurement and scrolling performance, especially on iOS where headers update as you scroll.
238
+
239
+
### stickyHeaderTopPadding
240
+
241
+
```ts
242
+
stickyHeaderTopPadding: boolean|number
243
+
```
244
+
245
+
Controls the padding applied to the sticky header at the top. Set to `false` to disable the extra top padding; set to a number to supply an explicit padding value.
246
+
247
+
### showSearch
248
+
249
+
```ts
250
+
showSearch: boolean
251
+
```
252
+
253
+
Shows a built-in search bar above the ListView. This is useful when you want a declarative, per-list search input without adding a separate `SearchBar` component.
254
+
255
+
### searchAutoHide
256
+
257
+
```ts
258
+
searchAutoHide: boolean
259
+
```
260
+
261
+
(iOS only) When `true`, the built-in search bar will auto-hide when the user scrolls. This mirrors common iOS list behaviors.
262
+
131
263
### separatorColor
132
264
133
265
```ts
@@ -150,6 +282,8 @@ rowHeight: number
150
282
151
283
Gets or sets the row height of the ListView. Useful when your items have a fixed height, as the required calculations are greatly simplified and the rendering can be faster.
152
284
285
+
> Android: with the latest ListView improvements, row items will now react properly to spacing (padding and margin), so setting `rowHeight` alongside your layout spacing should behave more predictably across platforms.
286
+
153
287
### iosEstimatedRowHeight
154
288
155
289
Gets or sets the estimated height of rows in the ListView. Default value: `44px`
0 commit comments