> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/configuring-data-grouping.md).

# Configuring Data Grouping

Group Data Table rows under collapsible headers by stage, owner or account, and order the groups the way your team reads the pipeline.

A sales manager reviewing the pipeline wants to see deals stage by stage, in sales order, with a count on each stage. Grouping puts every row under a header for its value in one field, such as **Stage**, and each header can be collapsed.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FCJneWgTSh80lOVKyEPtO%2Fdata-table-tutorial-configuring-data-grouping-result.png?alt=media" alt="A Data Table titled Pipeline by stage with open deals grouped under collapsible headers Prospecting (1), Qualification (4), Needs Analysis (4), Value Proposition (1), Proposal/Price Quote (4) and Negotiation/Review (3), rows sorted by amount"><figcaption><p>Open deals grouped by stage, in sales order, with the number of deals on each header.</p></figcaption></figure>

## Before you start

* A Data Table with a **Query** data source. Grouping is not available with the Manual or Variable data sources. See [Data Table](https://docs.avonnicomponents.com/dynamic-components/components/data-table.md) and [Query](https://docs.avonnicomponents.com/dynamic-components/component-builder/data-sources/query.md).
* The field you group by does not have to be a column, but it must be a field Salesforce can group on. Long text area fields, for example, are not offered.

## Steps

{% stepper %}
{% step %}

### Choose the field to group by

1. Select the Data Table on the canvas.
2. In the Properties panel, open the **Data Mappings** section.
3. In **Group By**, pick the field, for example **Stage** (`StageName`).

The table regroups on the canvas right away.
{% endstep %}

{% step %}

### Put the groups in sales order

Open the **Group By** section of the Properties panel and set **Direction**:

* **Ascending Order** and **Descending Order** sort the group labels alphabetically. For stages this puts Closed Lost before Prospecting, which is rarely what a sales team wants.
* **Custom** shows **Group By Custom Order**, a list of values in the order you want the groups. On a picklist field the list starts with the picklist values, in picklist order, which for **Stage** is already the sales order.

{% hint style="warning" %}
With **Custom**, a group whose value is not in the list is not displayed. Remove `Closed Won` and `Closed Lost` from the list and the table shows open deals only. Add a value back if a group disappears unexpectedly.
{% endhint %}

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fypwv2PMbwyRQk89sGcaE%2Fdata-table-tutorial-configuring-data-grouping-group-by-panel.png?alt=media" alt="The Group By section of the Data Table Properties panel with Display Group Rows Count on, Direction set to Custom and a Group By Custom Order list from Prospecting to Negotiation/Review" width="320"><figcaption><p>Direction set to Custom, with the closed stages removed from Group By Custom Order.</p></figcaption></figure>
{% endstep %}

{% step %}

### Decide how the groups open

Still in the **Group By** section:

* **Display Group Rows Count** adds the number of rows next to each header, for example `Qualification (3)`.
* **Collapsed** loads the table with every group closed. Use it on long tables so the reader starts from the overview.
* **Non Collapsible** keeps every group open and removes the collapse control. **Collapsed** is hidden while it is on.
  {% endstep %}

{% step %}

### Handle blank and empty values

* Records with a blank value land in one group, labelled **Undefined** by default and always shown last. Rename it in **Undefined Group Label**, for example `No stage`.
* **Hide Undefined Group** removes that group and its rows from the table.
* **Show Empty Groups** adds a header for every picklist value, even when no record has it. It only works when the group field is a picklist.
  {% endstep %}

{% step %}

### Make lookup headers clickable (optional)

When you group by a lookup, such as **Account** (`AccountId`), turn on **Linkify** in the **Group By** section. Each header becomes a link to the account record. **Linkify** has no effect on other field types.
{% endstep %}

{% step %}

### Sort the rows inside each group

Grouping decides the buckets, sorting decides the order inside them. In **Data Mappings**, set **Sort By** to a field such as **Amount** or **Close Date**, and pick the order in **Sorted Direction**, in the **Sort** section.
{% endstep %}

{% step %}

### Save and test

Save the component and open the page that hosts it. Each stage appears as a header in the order of your custom list, with its row count, and clicking a header collapses or expands its deals.
{% endstep %}
{% endstepper %}

## Troubleshooting

<details>

<summary>A group is missing</summary>

**Direction** is set to **Custom** and the value is not in **Group By Custom Order**. Add it to the list. If the list is empty, no group is displayed at all.

</details>

<details>

<summary>The table keeps loading after the component JSON was edited by hand</summary>

When you pick a field in **Group By**, the builder also writes the binding that tells the table how many records each group holds. A component edited outside the builder can lose it. Open the component in the builder and select the **Group By** field again, then save.

</details>

<details>

<summary>The field I want is not in the Group By list</summary>

The list only shows fields Salesforce can group on. Create a formula or picklist field on the object that holds the value you want to group by, then select it.

</details>

## Related tutorials

* [Add Subtotals and Totals](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/add-subtotals-and-totals.md): show the total amount of each stage next to its header.
* [Apply Badge Color-Coding](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/apply-badge-color-coding.md): color each stage so late and closed deals stand out.
* [Add User Filters](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/add-user-filters.md): let the reader narrow the grouped table to their own deals.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/configuring-data-grouping.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
