CxJS

Lookup Options Grouping

Since LookupField uses a List widget internally to render dropdown contents, you can specify grouping configuration through the listOptions property to organize options into groups.

Single Level Grouping

Group options by a single key with custom headers and footers. This example groups browsers by favorite status, showing favorites first with a star icon.

<LabelsTopLayout controller={PageController}>
  <LookupField
    label="Browser"
    value={m.browser}
    options={m.browserOptions}
    listOptions={{
      grouping: {
        key: {
          group: {
            value: { expr: "{$option.favorite} ? 'Favorites' : 'Other'" },
            direction: "ASC",
          },
        },
        header: (
          <FirstVisibleChildLayout>
            <div class="flex items-center gap-1.5 text-xs uppercase font-semibold text-gray-500 p-2">
              <Icon name="star" visible={equal(m.$group.group, "Favorites")} />
              <div text={m.$group.group} />
            </div>
          </FirstVisibleChildLayout>
        ),
      },
      itemStyle: "padding-left: 24px;",
    }}
  />
</LabelsTopLayout>
 

Multiple Level Grouping

For hierarchical grouping, pass an array of grouping configurations. This example groups users first by operating system, then by browser.

<div
  layout={{ type: LabelsTopLayout, vertical: true }}
  controller={PageController}
>
  <LookupField
    label="User"
    value={m.user}
    options={m.userOptions}
    optionTextField="fullName"
    listOptions={{
      grouping: [
        {
          key: {
            os: {
              value: { bind: "$option.os" },
              direction: "ASC",
            },
          },
          header: <div text={m.$group.os} class="font-bold p-2" />,
        },
        {
          key: {
            browser: {
              value: { bind: "$option.browser" },
              direction: "ASC",
            },
          },
          header: (
            <div
              text={m.$group.browser}
              class="text-xs uppercase font-semibold text-gray-500 py-2 pl-6"
            />
          ),
        },
      ],
      itemStyle: "padding-left: 40px;",
    }}
  />
</div>
 

Configuration

PropertyTypeDescription
listOptions.groupingobject or arraySingle grouping config or array for multi-level
listOptions.itemStylestringCSS style applied to each option item

Grouping Object

PropertyTypeDescription
keyobjectFields to group by with value binding and direction
aggregatesobjectAggregate calculations (count, sum, etc.)
headerwidgetWidget rendered before each group
footerwidgetWidget rendered after each group