Class CardSection

CardSection

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

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

const image = CardService.newImage();
// Build image ...
const textParagraph = CardService.newTextParagraph();
// Build text paragraph ...

const cardSection = CardService.newCardSection()
                        .setHeader('Section header')
                        .addWidget(image)
                        .addWidget(textParagraph);

Methods

MethodReturn typeBrief description
addWidget(widget)CardSectionAdds the given widget to this section.
setCollapseControl(collapseControl)CardSectionSets the customizable expand and collapse buttons of the section.
setCollapsible(collapsible)CardSectionSets whether the section can be collapsed.
setHeader(header)CardSectionSets the header of the section.
setNumUncollapsibleWidgets(numUncollapsibleWidgets)CardSectionSets 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
widgetWidgetA 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.

Only available for Google Chat apps. Not available for Google Workspace Add-ons.

const collapseButton =
    CardService.newTextButton()
        .setTextButtonStyle(CardService.TextButtonStyle.BORDERLESS)
        .setText('show less');

const expandButton =
    CardService.newImageButton()
        .setImageButtonStyle(CardService.ImageButtonStyle.FILLED)
        .setMaterialIcon(CardService.newMaterialIcon().setName('bug_report'));

const collapsibleSection =
    CardService.newCardSection()
        .setCollapsible(true)
        .setNumUncollapsibleWidgets(1)
        .setCollapseControl(
            CardService.newCollapseControl()
                .setHorizontalAlign(CardService.HorizontalAlignment.CENTER)
                .setCollapseButton(collapseButton)
                .setExpandButton(expandButton),
        );

Parameters

NameTypeDescription
collapseControlCollapseControlThe 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.