Class CardSection

  • Card sections visually separate groups of widgets within Google Workspace add-ons and Chat apps.

  • They can be customized with headers and configured to be collapsible, showing a specified number of widgets when collapsed.

  • Developers can easily add widgets like images and text paragraphs to card sections using Apps Script.

  • Card sections enhance the organization and user experience by grouping related content within cards.

CardSection

A card section holds groups of widgets and provides visual separation between them.

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

constimage=CardService.newImage();
// Build image ...
consttextParagraph=CardService.newTextParagraph();
// Build text paragraph ...
constcardSection=CardService.newCardSection()
.setHeader('Section header')
.addWidget(image)
.addWidget(textParagraph);

Methods

MethodReturn typeBrief description
addWidget(widget) CardSection Adds the given widget to this section.
setCollapseControl(collapseControl) CardSection Sets the customizable expand and collapse buttons of the section.
setCollapsible(collapsible) CardSection Sets whether the section can be collapsed.
setHeader(header) CardSection Sets the header of the section.
setNumUncollapsibleWidgets(numUncollapsibleWidgets) CardSection Sets the number of widgets that are still shown when this section is collapsed.

Detailed documentation

addWidget(widget)

Adds the given widget to this section. Widgets are shown in the order they were added. You can't add more than 100 widgets to a card section.

Parameters

NameTypeDescription
widgetWidget A widget to add to the section.

Return

CardSection — This object, for chaining.


setCollapseControl(collapseControl)

Sets the customizable expand and collapse buttons of the section. These buttons are shown only if the section is collapsible. If this field isn't set, default buttons are used.

Available for Google Chat apps. In developer preview for Google Workspace add-ons.

constcollapseButton=
CardService.newTextButton()
.setTextButtonStyle(CardService.TextButtonStyle.BORDERLESS)
.setText('show less');
constexpandButton=
CardService.newImageButton()
.setImageButtonStyle(CardService.ImageButtonStyle.FILLED)
.setMaterialIcon(CardService.newMaterialIcon().setName('bug_report'));
constcollapsibleSection=
CardService.newCardSection()
.setCollapsible(true)
.setNumUncollapsibleWidgets(1)
.setCollapseControl(
CardService.newCollapseControl()
.setHorizontalAlign(CardService.HorizontalAlignment.CENTER)
.setCollapseButton(collapseButton)
.setExpandButton(expandButton),
);

Parameters

NameTypeDescription
collapseControlCollapseControl The collapse control setting.

Return

CardSection — This object, for chaining.


setCollapsible(collapsible)

Sets whether the section can be collapsed.

Parameters

NameTypeDescription
collapsibleBooleanThe collapsible setting.

Return

CardSection — This object, for chaining.


setHeader(header)

Sets the header of the section. Optional.

Parameters

NameTypeDescription
headerStringThe header text.

Return

CardSection — This object, for chaining.


setNumUncollapsibleWidgets(numUncollapsibleWidgets)

Sets the number of widgets that are still shown when this section is collapsed. The widgets shown are always the first ones that were added.

Parameters

NameTypeDescription
numUncollapsibleWidgetsIntegerThe number of widgets to show.

Return

CardSection — 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.