CxJS

Complex Headers

Grid supports up to three header rows. Header cells can span multiple columns or rows using colSpan and rowSpan attributes, similar to HTML tables.

<Grid
  controller={PageController}
  records={m.records}
  style="width: 100%"
  border
  vlines
  columns={[
    {
      header1: { text: "Name", rowSpan: 2 },
      field: "fullName",
      sortable: true,
    },
    {
      align: "center",
      header1: { text: "Contact", colSpan: 2 },
      header2: "Phone",
      field: "phone",
    },
    {
      header2: "Email",
      field: "email",
      sortable: true,
    },
    {
      header1: { text: "Address", colSpan: 2, align: "center" },
      header2: "City",
      field: "city",
      sortable: true,
    },
    {
      header2: "Country",
      field: "country",
      sortable: true,
    },
  ]}
/>
NameContactAddress
PhoneEmailCityCountry
Alice Johnson555-1001[email protected]New YorkUSA
Bob Smith555-1002[email protected]Los AngelesUSA
Carol White555-1003[email protected]ChicagoCanada
David Brown555-1004[email protected]HoustonMexico
Eva Green555-1005[email protected]PhoenixUSA

Multiple Header Rows

Use header1, header2, and header3 to define content for each header row:

columns={[
  {
    header1: { text: "Name", rowSpan: 2 },
    field: "fullName",
  },
  {
    header1: { text: "Contact", colSpan: 2 },
    header2: "Phone",
    field: "phone",
  },
  {
    header2: "Email",
    field: "email",
  },
]}

Header Configuration

Each header can be a simple string or an object with these properties:

PropertyTypeDescription
textstringHeader text content.
colSpannumberNumber of columns to span.
rowSpannumberNumber of rows to span.
alignstringText alignment: left, center, or right.
allowSortingbooleanSet to false to disable sorting when clicking this header cell.
styleobjectCustom CSS styles for the header cell.
classNamestringCustom CSS class for the header cell.
itemsanyCustom content to render inside the header cell.

Tips

  • When using colSpan, subsequent columns should not define that header row (e.g., if header1 spans 2 columns, the next column should only define header2).
  • Use rowSpan: 2 on a header to make it span both header1 and header2 rows.
  • Add vlines prop to the Grid for vertical lines between columns, which helps visualize complex headers.

See also: Grid, Header Menu