# LazyGridScope

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/grid/LazyGridDsl.kt+class:androidx.compose.foundation.lazy.grid.LazyGridScope) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0) Common/All
- Cmn

  ```
  @LazyGridScopeMarker
  sealed interface LazyGridScope
  ```

*** ** * ** ***

Receiver scope which is used by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyVerticalGrid.composable#LazyVerticalGrid(androidx.compose.foundation.lazy.grid.GridCells,androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.grid.LazyGridState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,androidx.compose.foundation.lazy.layout.LazyLayoutCacheWindow,kotlin.Function1)`.

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#item(kotlin.Any,kotlin.Function1,kotlin.Any,kotlin.Function1)( key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.() -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)?, contentType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds a single item to the scope. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#items(kotlin.Int,kotlin.Function1,kotlin.Function2,kotlin.Function1,kotlin.Function2)( count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, key: ((index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)?, span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)?, contentType: (index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#items(kotlin.Int,kotlin.Function1,kotlin.Function2,kotlin.Function1,kotlin.Function2)` of items. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#stickyHeader(kotlin.Any,kotlin.Any,kotlin.Function2)(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, contentType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Adds a sticky header item, which will remain pinned even when scrolling after it. | Cmn |

| ### Extension functions |
|---|---|---|
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope.https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#(androidx.compose.foundation.lazy.grid.LazyGridScope).items(kotlin.Array,kotlin.Function1,kotlin.Function2,kotlin.Function1,kotlin.Function2)( items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<T>, noinline key: ((item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)?, noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)?, noinline contentType: (item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds an array of items. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope.https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#(androidx.compose.foundation.lazy.grid.LazyGridScope).items(kotlin.collections.List,kotlin.Function1,kotlin.Function2,kotlin.Function1,kotlin.Function2)( items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>, noinline key: ((item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)?, noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)?, noinline contentType: (item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds a list of items. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope.https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#(androidx.compose.foundation.lazy.grid.LazyGridScope).itemsIndexed(kotlin.Array,kotlin.Function2,kotlin.Function3,kotlin.Function2,kotlin.Function3)( items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<T>, noinline key: ((index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)?, noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)?, crossinline contentType: (index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds an array of items where the content of an item is aware of its index. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope.https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#(androidx.compose.foundation.lazy.grid.LazyGridScope).itemsIndexed(kotlin.collections.List,kotlin.Function2,kotlin.Function3,kotlin.Function2,kotlin.Function3)( items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>, noinline key: ((index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)?, noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)?, crossinline contentType: (index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds a list of items where the content of an item is aware of its index. | Cmn |

## Public functions

### item

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)

```
fun item(
    key: Any? = null,
    span: (LazyGridItemSpanScope.() -> GridItemSpan)? = null,
    contentType: Any? = null,
    content: @Composable LazyGridItemScope.() -> Unit
): Unit
```

Adds a single item to the scope.

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = null` | a stable and unique key representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one. This can be overridden by calling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridState#requestScrollToItem(kotlin.Int,kotlin.Int)`. |
| `span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.() -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)? = null` | the span of the item. Default is 1x1. It is good practice to leave it `null` when this matches the intended behavior, as providing a custom implementation impacts performance |
| `contentType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = null` | the type of the content of this item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible. |
| `content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the content of the item |

### items

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)

```
fun items(
    count: Int,
    key: ((index: Int) -> Any)? = null,
    span: (LazyGridItemSpanScope.(index: Int) -> GridItemSpan)? = null,
    contentType: (index: Int) -> Any? = { null },
    itemContent: @Composable LazyGridItemScope.(index: Int) -> Unit
): Unit
```

Adds a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridScope#items(kotlin.Int,kotlin.Function1,kotlin.Function2,kotlin.Function1,kotlin.Function2)` of items.

| Parameters |
|---|---|
| `count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the items count |
| `key: ((index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)? = null` | a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.This can be overridden by calling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridState#requestScrollToItem(kotlin.Int,kotlin.Int)`. |
| `span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)? = null` | define custom spans for the items. Default is 1x1. It is good practice to leave it `null` when this matches the intended behavior, as providing a custom implementation impacts performance |
| `contentType: (index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = { null }` | a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible. |
| `itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the content displayed by a single item |

### stickyHeader

Cmn Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
fun stickyHeader(
    key: Any? = null,
    contentType: Any? = null,
    content: @Composable LazyGridItemScope.(Int) -> Unit
): Unit
```

Adds a sticky header item, which will remain pinned even when scrolling after it. The header will remain pinned until the next header will take its place. Sticky Headers are full span items, that is, they will occupy `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope#maxLineSpan()`.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

val sections = listOf("A", "B", "C", "D", "E", "F", "G")

LazyVerticalGrid(columns = GridCells.Fixed(3), contentPadding = PaddingValues(6.dp)) {
    sections.forEach { section ->
        stickyHeader {
            Text(
                "Section $section",
                Modifier.fillMaxWidth().background(Color.LightGray).padding(8.dp),
            )
        }
        items(10) { Text("Item= $it S=$section", modifier = Modifier.height(64.dp)) }
    }
}
```

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = null` | a stable and unique key representing the item. Using the same key for multiple items in the list is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the list will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one. This can be overridden by calling 'requestScrollToItem' on the 'LazyGridState'. |
| `contentType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = null` | the type of the content of this item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible. |
| `content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the content of the header. The header index is provided, this is the item position within the total set of items in this lazy list (the global index). |

## Extension functions

### LazyGridScope.items

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/grid/LazyGridDsl.kt+function:items)

```
inline fun <T : Any?> LazyGridScope.items(
    items: Array<T>,
    noinline key: ((item) -> Any)? = null,
    noinline span: (LazyGridItemSpanScope.(item) -> GridItemSpan)? = null,
    noinline contentType: (item) -> Any? = { null },
    crossinline itemContent: @Composable LazyGridItemScope.(item) -> Unit
): Unit
```

Adds an array of items.

| Parameters |
|---|---|
| `items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<T>` | the data array |
| `noinline key: ((item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)? = null` | a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.This can be overridden by calling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridState#requestScrollToItem(kotlin.Int,kotlin.Int)`. |
| `noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)? = null` | define custom spans for the items. Default is 1x1. It is good practice to leave it `null` when this matches the intended behavior, as providing a custom implementation impacts performance |
| `noinline contentType: (item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = { null }` | a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible. |
| `crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the content displayed by a single item |

### LazyGridScope.items

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/grid/LazyGridDsl.kt+function:items)

```
inline fun <T : Any?> LazyGridScope.items(
    items: List<T>,
    noinline key: ((item) -> Any)? = null,
    noinline span: (LazyGridItemSpanScope.(item) -> GridItemSpan)? = null,
    noinline contentType: (item) -> Any? = { null },
    crossinline itemContent: @Composable LazyGridItemScope.(item) -> Unit
): Unit
```

Adds a list of items.

| Parameters |
|---|---|
| `items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>` | the data list |
| `noinline key: ((item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)? = null` | a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one. This can be overridden by calling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridState#requestScrollToItem(kotlin.Int,kotlin.Int)`. |
| `noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)? = null` | define custom spans for the items. Default is 1x1. It is good practice to leave it `null` when this matches the intended behavior, as providing a custom implementation impacts performance |
| `noinline contentType: (item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = { null }` | a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible. |
| `crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the content displayed by a single item |

### LazyGridScope.itemsIndexed

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/grid/LazyGridDsl.kt+function:itemsIndexed)

```
inline fun <T : Any?> LazyGridScope.itemsIndexed(
    items: Array<T>,
    noinline key: ((index: Int, item) -> Any)? = null,
    noinline span: (LazyGridItemSpanScope.(index: Int, item) -> GridItemSpan)? = null,
    crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null },
    crossinline itemContent: @Composable LazyGridItemScope.(index: Int, item) -> Unit
): Unit
```

Adds an array of items where the content of an item is aware of its index.

| Parameters |
|---|---|
| `items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<T>` | the data array |
| `noinline key: ((index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)? = null` | a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one. This can be overridden by calling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridState#requestScrollToItem(kotlin.Int,kotlin.Int)`. |
| `noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)? = null` | define custom spans for the items. Default is 1x1. It is good practice to leave it `null` when this matches the intended behavior, as providing a custom implementation impacts performance |
| `crossinline contentType: (index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = { _, _ -> null }` | a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible. |
| `crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the content displayed by a single item |

### LazyGridScope.itemsIndexed

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/grid/LazyGridDsl.kt+function:itemsIndexed)

```
inline fun <T : Any?> LazyGridScope.itemsIndexed(
    items: List<T>,
    noinline key: ((index: Int, item) -> Any)? = null,
    noinline span: (LazyGridItemSpanScope.(index: Int, item) -> GridItemSpan)? = null,
    crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null },
    crossinline itemContent: @Composable LazyGridItemScope.(index: Int, item) -> Unit
): Unit
```

Adds a list of items where the content of an item is aware of its index.

| Parameters |
|---|---|
| `items: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>` | the data list |
| `noinline key: ((index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)? = null` | a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one. This can be overridden by calling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridState#requestScrollToItem(kotlin.Int,kotlin.Int)`. |
| `noinline span: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemSpanScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/GridItemSpan)? = null` | define custom spans for the items. Default is 1x1. It is good practice to leave it `null` when this matches the intended behavior, as providing a custom implementation impacts performance |
| `crossinline contentType: (index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? = { _, _ -> null }` | a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible. |
| `crossinline itemContent: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/LazyGridItemScope.(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, item) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the content displayed by a single item |