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 ( |
Fields | |
---|---|
title
|
The text that displays in the grid header. |
items[]
|
The items to display in the grid. |
borderStyle
|
The border style to apply to each grid item. |
columnCount
|
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
|
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 ( |
Fields | |
---|---|
id
|
A user-specified identifier for this grid item. This identifier is returned in the parent Grid's onClick callback parameters. |
image
|
The image that displays in the grid item. |
title
|
The grid item's title. |
subtitle
|
The grid item's subtitle. |
layout
|
The layout to use for the grid item. |
BorderStyle
JSON representation |
---|
{ "type": enum ( |
Fields | |
---|---|
type
|
The border type. |
strokeColor
|
The colors to use when the type is
|
cornerRadius
|
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 |
Fields | |
---|---|
Union field
|
|
action
|
If specified, an action is triggered by this
|
openLink
|
If specified, this
|
openDynamicLinkAction
|
An add-on triggers this action when the action needs to open a link. This differs from the
|
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 ( |
Fields | |
---|---|
function
|
A custom function to invoke when the containing element is clicked or othrwise activated. For example usage, see Create interactive cards . |
parameters[]
|
List of action parameters. |
loadIndicator
|
Specifies the loading indicator that the action displays while making the call to the action. |
persistValues
|
Indicates whether form values persist after the action. The default value is
If
If
|
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
By specifying an
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
|
The name of the parameter for the action script. |
value
|
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. |
OpenLink
Represents an
onClick
event that opens a hyperlink.
JSON representation |
---|
{ "url": string, "openAs": enum ( |
Fields | |
---|---|
url
|
The URL to open. |
openAs
|
How to open a link. Not supported by Chat apps. |
onClose
|
Whether the client forgets about a link after opening it, or observes it until the window closes. Not supported by Chat apps. |