# Grid >![](../../public_sys-resources/icon-note.gif) **NOTE:** >This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. The **** component is a two-dimensional layout. The component is divided into rows and columns, to form cells. You can specify the cell where an item is located and combine different grids to form various layouts. ## Required Permissions None ## Child Components This component contains the child component [](ts-container-griditem.md). ## APIs Grid\(\) ## Attributes

Name

Type

Default Value

Description

columnsTemplate

string

'1fr'

Number of columns in the current grid layout. If this parameter is not set, one column is used by default. For example, '1fr 1fr 2fr' divides the component into three columns, with four equal parts. The first column occupies one part, the second column occupies one part, and the third column occupies two parts.

rowsTemplate

string

'1fr'

Number of rows in the current grid layout. If this parameter is not set, one row is used by default. For example, '1fr 1fr 2fr' divides the component into three rows. The width allowed by the parent component is divided into four equal parts. The first row occupies one part, the second row occupies one part, and the third row occupies two parts.

columnsGap

Length

0

Spacing between columns.

rowsGap

Length

0

Spacing between rows.

## Events

Name

Description

onScrollIndex(first: number) => void

Triggered when the start item of the grid changes.

## Example ``` @Entry @Component struct GridExample { @State Number: String[] = ['0', '1', '2', '3', '4'] build() { Column({ space: 5 }) { Grid() { ForEach(this.Number, (day: string) => { ForEach(this.Number, (day: string) => { GridItem() { Text(day) .fontSize(16) .backgroundColor(0xF9CF93) .width('100%') .height('100%') .textAlign(TextAlign.Center) } }, day => day) }, day => day) } .columnsTemplate('1fr 1fr 1fr 1fr 1fr') .rowsTemplate('1fr 1fr 1fr 1fr 1fr') .columnsGap(10) .rowsGap(10) .width('90%') .backgroundColor(0xFAEEE0) .height(300) Text('scroll').fontColor(0xCCCCCC).fontSize(9).width('90%') Grid() { ForEach(this.Number, (day: string) => { ForEach(this.Number, (day: string) => { GridItem() { Text(day) .fontSize(16) .backgroundColor(0xF9CF93) .width('100%') .height(80) .textAlign(TextAlign.Center) } }, day => day) }, day => day) } .columnsTemplate('1fr 1fr 1fr 1fr 1fr') .columnsGap(10) .rowsGap(10) .onScrollIndex((first: number) => { console.info(first.toString()) }) .width('90%') .backgroundColor(0xFAEEE0) .height(300) }.width('100%').margin({ top: 5 }) } } ``` ![](figures/grid-3.gif)