Grid

Stay organized with collections Save and categorize content based on your preferences.

Only supported in dialogs. Support for card messages coming soon.

A 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",
                  "numColumns": 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"
                    }
                  }
                }
              }
            ]
          }
        ]
      }
    }
  ]
}

Grid 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.

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, an Apps Script can be invoked 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 button on 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 is not 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.

ActionParameter

List of string parameters to supply when the action method is invoked. For example, consider three snooze buttons: snooze now, snooze 1 day, snooze next week. You might use action method = snooze(), passing the snooze type and snooze time in the list of string parameters.

To learn more, see CommonEventObject .

JSON representation
{
  "key": string,
  "value": string
}
Fields
key

string

The name of the parameter for the action script.

value

string

The value of the parameter.

LoadIndicator

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

Enums
SPINNER Displays a spinner to indicate that content is loading.
NONE Nothing is displayed.

Interaction

Optional. Required when opening a dialog .

What to do in response to an interaction with a user, such as a user clicking button on 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 is not 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.

Enums
INTERACTION_UNSPECIFIED Default value. The action executes as normal.
OPEN_DIALOG

Opens a dialog , a windowed, card-based interface that Chat apps use to interact with users.

Only supported by Chat apps in response to button-clicks on card messages.

Not supported by Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.