Class GridItem

  • GridItem represents interactive elements within a grid widget, usable in Google Workspace Add-ons and Chat apps.

  • Developers can set an identifier, image, layout, subtitle, text alignment, and title for each GridItem.

  • When a user clicks a GridItem, its identifier is returned in the parent grid's on_click callback, enabling interactive functionality.

  • GridItem leverages CardService methods for customization, such as setTitle(), setImage(), and setLayout(), to define its appearance and behavior.

  • Default settings include TEXT_BELOW for layout and START for text alignment, offering a base configuration for GridItems.

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.

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

Methods

MethodReturn typeBrief description
setIdentifier(id)GridItemSets the identifier for the grid item.
setImage(image)GridItemSets the image for this grid item.
setLayout(layout)GridItemSets the layout of text and image for the grid item.
setSubtitle(subtitle)GridItemSets the subtitle of the grid item.
setTextAlignment(alignment)GridItemSets the horizontal alignment of the grid item.
setTitle(title)GridItemSets 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
imageImageComponentThe 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
layoutGridItemLayoutThe 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
alignmentHorizontalAlignmentThe 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.