> 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/reactive-components/data-relationships/master-detail-relationship-with-data-tables.md).

# Master-Detail Relationship with Data Tables

## Overview

This tutorial demonstrates how to create a classic *master-detail* relationship between two Avonni [Data Table](https://docs.avonnicomponents.com/dynamic-components/components/data-table.md) components. You'll build a component where:

* One Data Table (the "master") displays a list of Accounts.
* A second Data Table (the "detail") displays Contacts *related to the currently selected Account*.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fgit-blob-d3da3958d793a7740fa9d758470873dcd5676ed9%2F2025-03-19_20-07-18%20(1).gif?alt=media" alt=""><figcaption></figcaption></figure>

Setting up a reactive filter on the data source of the detail table is key. This filter dynamically updates based on the selected row in the master table, ensuring that only the relevant Contacts are displayed. This creates a seamless and interactive user experience.

We will be following those steps:

* Set up the account table, also called the master table.
* Set up the contact table, the details one.
* Create the reactive filter to link those two tables.
* Test

## Guided Steps

{% stepper %}
{% step %}

#### **Set Up the Accounts Data Table (Mast**

* Add an Avonni Data Table component to your page.
* Configure its data source to display a list of Accounts (using a Query).
  {% endstep %}

{% step %}

#### **Set Up the Contacts Data Table (Detail**

* Add another Avonni Data Table component to your page.
* Configure its data source to display Contacts (using the **Avonni Query Data Source**).

{% hint style="success" %}

## Handy Tip

You can use a [column component](https://docs.avonnicomponents.com/dynamic-components/components/columns.md) to display your two data tables side by side.
{% endhint %}
{% endstep %}

{% step %}

#### **Create the Reactive Filter**

* **Add a Filter Condition:**
  * **Field:** Select the `AccountId` field on the Contact object (or the field linking Contacts to Accounts).
  * **Operator:** Choose `equals`.
  * **Value:** *Do not enter a fixed value.* Instead, reference the selected Account's ID:

    ```
    !AccountsTable.firstSelectedRow.Id
    ```

    * **Explanation:**
      * `!AccountsTable`: Your Accounts Data Table component (use the API *name*).
      * `.firstSelectedRow`: The currently selected row in the Accounts table.
      * `.Id`: The `Id` field from that selected row.
  * Make sure to use the correct names for the component and field.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fgit-blob-6ac85bd4ce3edaa18316a7d304159013328f3b4f%2F2025-03-19_20-04-38%20(1).gif?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### **Test the Reactivity**

* Preview your page.
* Select different Accounts in the Accounts Data Table. The Contacts Data Table should automatically update.
  {% endstep %}
  {% endstepper %}


---

# 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/reactive-components/data-relationships/master-detail-relationship-with-data-tables.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.
