CxJS

Row Expanding

Grid supports rendering rows with multiple lines. Lines can be shown or hidden dynamically, enabling drill-down functionality and on-demand content display.

<Grid
  controller={PageController}
  records={m.records}
  style="width: 100%"
  border
  lockColumnWidths
  row={{
    style: {
      background: expr(m.$record.expanded, (expanded) =>
        expanded ? "#fff7e6" : null,
      ),
    },
    line1: {
      columns: [
        { header: "Name", field: "fullName", sortable: true },
        { header: "Continent", field: "continent", sortable: true },
        { header: "Browser", field: "browser", sortable: true },
        { header: "Visits", field: "visits", sortable: true, align: "right" },
        {
          align: "center",
          pad: false,
          items: (
            <Button
              mod="hollow"
              icon="drop-down"
              onClick={(e, { store }) => {
                store.toggle(m.$record.expanded)
              }}
            />
          ),
        },
      ],
    },
    line2: {
      visible: m.$record.expanded,
      columns: [
        {
          colSpan: 1000,
          style: "border-top-color: rgba(0, 0, 0, 0.05); padding: 16px;",
          items: (
            <div>
              <strong>Bio: </strong>
              <span text={m.$record.bio} />
            </div>
          ),
        },
      ],
    },
  }}
/>
NameContinentBrowserVisits
Alice JohnsonEuropeChrome45
Bob SmithAsiaFirefox23
Carol WhiteNorth AmericaSafari67
David BrownEuropeChrome12
Eva GreenAsiaEdge89

Click the arrow button to expand a row and see additional details.

Multi-line Rows

Use the row property with line1, line2, etc. to define multiple row lines:

<Grid
  records={m.records}
  row={{
    line1: {
      columns: [
        { header: "Name", field: "fullName" },
        // ... main columns
      ],
    },
    line2: {
      visible: m.$record.expanded,
      columns: [
        {
          colSpan: 1000,
          items: <div text={m.$record.details} />,
        },
      ],
    },
  }}
/>

Controlling Visibility

Bind line visibility to record state:

line2: {
  visible: m.$record.expanded,
  columns: [/* ... */],
}

Toggle expansion with a button:

<Button
  icon="drop-down"
  onClick={(e, { store }) => {
    store.toggle(m.$record.expanded);
  }}
/>

Styling Expanded Rows

Use expr to conditionally style expanded rows:

row={{
  style: {
    background: expr(m.$record.expanded, (expanded) =>
      expanded ? "#fff7e6" : null
    ),
  },
  // ...
}}

Configuration

PropertyTypeDescription
rowobjectRow configuration with line1, line2, etc.
line1, line2, …objectLine configuration with columns and visible.
visiblebooleanLine visibility. Can be bound to record state.
colSpannumberColumn span for expanded content. Use a large number like 1000 to span all columns.
lockColumnWidthsbooleanRecommended when using multi-line rows to prevent layout shifts.

See also: Grid, Row Drag and Drop