Class GridItem

  • GridItems are interactive elements within a grid widget, available for Google Workspace add-ons and Google Chat apps.

  • Enums like CardService.GridItemLayout.TEXT_BELOW are called by referencing their parent class, name, and property.

  • GridItem objects can be configured using methods such as setIdentifier, setImage, setLayout, setSubtitle, setTextAlignment, and setTitle.

  • The setIdentifier method assigns an ID that is returned in the parent grid's on_click callback.

  • Methods like setLayout and setTextAlignment have default values if not explicitly set.

GridItem

The items users interact with within a grid widget.

Available for Google Workspace add-ons and Google Chat apps.

To call an enum, you call its parent class, name, and property. For example, CardService.GridItemLayout.TEXT_BELOW.

constgridItem=CardService.newGridItem()
.setIdentifier('itemA')
.setTitle('This is a cat')
.setImage(CardService.newImageComponent())
.setLayout(CardService.GridItemLayout.TEXT_BELOW);

Methods

MethodReturn typeBrief description
setIdentifier(id) GridItem Sets the identifier for the grid item.
setImage(image) GridItem Sets the image for this grid item.
setLayout(layout) GridItem Sets the layout of text and image for the grid item.
setSubtitle(subtitle) GridItem Sets the subtitle of the grid item.
setTextAlignment(alignment) GridItem Sets the horizontal alignment of the grid item.
setTitle(title) GridItem Sets the title text of the grid item.

Detailed documentation

setIdentifier(id)

Sets the identifier for the grid item. When a user clicks this grid item, this ID is returned in the parent grid's on_click call back parameters.

Parameters

NameTypeDescription
idStringThe ID.

Return

GridItem — This object, for chaining.


setImage(image)

Sets the image for this grid item.

Parameters

NameTypeDescription
imageImageComponent The ImageComponent object.

Return

GridItem — This object, for chaining.


setLayout(layout)

Sets the layout of text and image for the grid item. Default is TEXT_BELOW

Parameters

NameTypeDescription
layoutGridItemLayout The layout setting.

Return

GridItem — This object, for chaining.


setSubtitle(subtitle)

Sets the subtitle of the grid item.

Parameters

NameTypeDescription
subtitleStringThe subtitle text.

Return

GridItem — This object, for chaining.


setTextAlignment(alignment)

Sets the horizontal alignment of the grid item. Default is START.

Parameters

NameTypeDescription
alignmentHorizontalAlignment The alignment setting.

Return

GridItem — This object, for chaining.


setTitle(title)

Sets the title text of the grid item.

Parameters

NameTypeDescription
titleStringThe title text.

Return

GridItem — This object, for chaining.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年01月30日 UTC.