Main Content

mlreportgen.dom.Collapsible Class

Namespace: mlreportgen.dom

Collapsible rows in HTML table

Since R2025a

Description

Use an object of the mlreportgen.dom.Collapsible class to specify the number of table rows to collapse in an HTML table.

The mlreportgen.dom.Collapsible class is a handle class.

Class Attributes

HandleCompatible
true
ConstructOnLoad
true

For information on class attributes, see Class Attributes.

Creation

Input Arguments

expand all

Number of rows after the formatted row to collapse, specified as an integer.

Properties

expand all

Number of rows to collapse, specified as an integer. The value of this property denotes the number of rows after the formatted row that collapse when you click the formatted row.

Attributes:

NonCopyable
true

Data Types: uint64

Tag, specified as a character vector or string scalar. The DOM API generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Use this value to help identify where an issue occurs during document generation.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Object identifier, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Examples

collapse all

This example shows how to create HTML tables with collapsible rows or with nested collapsible rows.

Create Table with Collapsible Rows

Import the mlreportgen.report and mlreportgen.dom namespaces so that you do not have to include the fully qualified names for the object constructors and methods.

import mlreportgen.report.*
import mlreportgen.dom.*

Create an HTML document.

rpt = Report("myCollapsibleTables","html");
open(rpt);

Create the first chapter.

chap1 = Chapter("Table with collapsible rows");

Specify the table data.

collapsibleTableData = { ...
    "Parent Row: Click to expand next 2 rows"; ...
    "  Collapsible Content for Parent Row"; ...
    "  More Collapsible Content for Parent Row"; ...
    "Static Row" ...
    };

Create the table and define basic styling. Use WhiteSpace("preserve") to keep the leading whitespaces in the second and third rows.

tbl = Table(collapsibleTableData);
tbl.Border = "solid";
tbl.RowSep = "solid";
tbl.ColSep = "solid";
tbl.Style = [tbl.Style {WhiteSpace("preserve")}];

Make the first row of the table collapsible, so that clicking on it collapses the following two rows.

row1 = tbl.row(1);
row1.Style = [row1.Style {Collapsible(2)}];

Append the table to the chapter and the chapter to the report.

append(chap1,tbl);
append(rpt,chap1);

Close and view the report.

close(rpt);
rptview(rpt);

To open or close a group of collapsible rows, click the parent row. Collapsible rows have gray highlighting when you point to them.

This image shows what the table looks like in the report when fully expanded and when the second row is collapsed.

Chapter 1 heading followed by a table with 4 rows. The rows describe their function as parent, collapsible, or static.

Table with all rows fully expanded

Chapter 1 heading followed by a table with 2 of the 4 rows collapsed.

Table with the second row collapsed

Version History

Introduced in R2025a