Grid

The Grid widget displays a grid with a collection of items.

The widget supports suggestions, which help users enter uniform data, and on-change actions, which are Actions that run when a change occurs in the text input field, like a user adding or deleting text.

A grid supports any number of columns and items. The number of rows is determined by items divided by columns. A grid with 10 items and 2 columns has 5 rows. A grid with 11 items and 2 columns has 6 rows.

Chat apps receive and can process the value of selected items during form input events. For details about working with form inputs, see Receive form data.

Example: a two-column grid with a single item

The following image displays a dialog consisting of a grid widget. It creates a 2 column grid with a single item.

Here's the card's JSON:

JSON

{
  "cardsV2": [
    {
      "cardId": "exampleCard",
      "card": {
        "sections": [
          {
            "widgets": [
              {
                "grid": {
                  "title": "A fine collection of items",
                  "columnCount": 2,
                  "borderStyle": {
                    "type": "STROKE",
                    "cornerRadius": 4.0
                  },
                  "items": [
                    {
                      "image": {
                        "imageUri": "https://developers.google.com/static/chat/images/chat-app-hero-image_1440.png",
                        "cropStyle": {
                          "type": "SQUARE"
                        },
                        "borderStyle": {
                          "type": "STROKE"
                        }
                      },
                      "title": "An item",
                      "textAlignment": "CENTER"
                    }
                  ],
                  "onClick": {
                    "openLink": {
                      "url": "https://developers.google.com/chat"
                    }
                  }
                }
              }
            ]
          }
        ]
      }
    }
  ]
}

JSON representation and fields

JSON representation
{
  "title": string,
  "items": [
    {
      object (GridItem)
    }
  ],
  "borderStyle": {
    object (BorderStyle)
  },
  "columnCount": integer,
  "onClick": {
    object (OnClick)
  }
}
Fields
title

string

The text that displays in the grid header.

items[]

object (GridItem)

The items to display in the grid.

borderStyle

object (BorderStyle)

The border style to apply to each grid item.

columnCount

integer

The number of columns to display in the grid. A default value is used if this field isn't specified, and that default value is different depending on where the grid is shown (dialog versus companion).

onClick

object (OnClick)

This callback is reused by each individual grid item, but with the item's identifier and index in the items list added to the callback's parameters.

GridItem

JSON representation
{
  "id": string,
  "image": {
    object (ImageComponent)
  },
  "title": string,
  "subtitle": string,
  "layout": enum (GridItemLayout)
}
Fields
id

string

A user-specified identifier for this grid item. This identifier is returned in the parent grid's onClick callback parameters.

image

object (ImageComponent)

The image that displays in the grid item.

title

string

The grid item's title.

subtitle

string

The grid item's subtitle.

layout

enum (GridItemLayout)

The layout to use for the grid item.

BorderStyle

JSON representation
{
  "type": enum (BorderType),
  "strokeColor": {
    object (Color)
  },
  "cornerRadius": integer
}
Fields
type

enum (BorderType)

The border type.

strokeColor

object (Color)

The colors to use when the type is BORDER_TYPE_STROKE.

cornerRadius

integer

The corner radius for the border.

BorderType

Enums
BORDER_TYPE_UNSPECIFIED No value specified.
NO_BORDER Default value. No border.
STROKE Outline.

Color

JSON representation
{
  "red": number,
  "green": number,
  "blue": number,
  "alpha": number
}
Fields
red

number

The amount of red in the color as a value in the interval [0, 1].

green

number

The amount of green in the color as a value in the interval [0, 1].

blue

number

The amount of blue in the color as a value in the interval [0, 1].

alpha

number

The fraction of this color that should be applied to the pixel. That is, the final pixel color is defined by the equation:

pixel color = alpha * (this color) + (1.0 - alpha) * (background color)

This means that a value of 1.0 corresponds to a solid color, whereas a value of 0.0 corresponds to a completely transparent color. This uses a wrapper message rather than a simple float scalar so that it is possible to distinguish between a default value and the value being unset. If omitted, this color object is rendered as a solid color (as if the alpha value had been explicitly given a value of 1.0).

OnClick

Represents how to respond when users click an interactive element on a card, such as a button.

JSON representation
{

  // Union field data can be only one of the following:
  "action": {
    object (Action)
  },
  "openLink": {
    object (OpenLink)
  },
  "openDynamicLinkAction": {
    object (Action)
  },
  "card": {
    object (Card)
  }
  // End of list of possible types for union field data.
}
Fields

Union field data.

data can be only one of the following:

action

object (Action)

If specified, an action is triggered by this onClick.

card

object (Card)

A new card is pushed to the card stack after clicking if specified.

Supported by Google Workspace Add-ons, but not Chat apps.

Action

An action that describes the behavior when the form is submitted. For example, you can invoke an Apps Script script to handle the form. If the action is triggered, the form values are sent to the server.

JSON representation
{
  "function": string,
  "parameters": [
    {
      object (ActionParameter)
    }
  ],
  "loadIndicator": enum (LoadIndicator),
  "persistValues": boolean,
  "interaction": enum (Interaction)
}
Fields
function

string

A custom function to invoke when the containing element is clicked or othrwise activated.

For example usage, see Create interactive cards.

parameters[]

object (ActionParameter)

List of action parameters.

loadIndicator

enum (LoadIndicator)

Specifies the loading indicator that the action displays while making the call to the action.

persistValues

boolean

Indicates whether form values persist after the action. The default value is false.

If true, form values remain after the action is triggered. To let the user make changes while the action is being processed, set LoadIndicator to NONE. For card messages in Chat apps, you must also set the action's ResponseType to UPDATE_MESSAGE and use the same cardId from the card that contained the action.

If false, the form values are cleared when the action is triggered. To prevent the user from making changes while the action is being processed, set LoadIndicator to SPINNER.

interaction

enum (Interaction)

Optional. Required when opening a dialog.

What to do in response to an interaction with a user, such as a user clicking a button in a card message.

If unspecified, the app responds by executing an action —like opening a link or running a function—as normal.

By specifying an interaction, the app can respond in special interactive ways. For example, by setting interaction to OPEN_DIALOG, the app can open a dialog. When specified, a loading indicator isn't shown.

Supported by Chat apps, but not Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.