# Advanced Data Settings

## Content

Advanced data settings extend column capabilities beyond basic structure and validation.
These settings enable:

* Computed columns
* Reactive recalculation
* Value domain definition
* Relationship-aware behavior

They introduce dynamic and relational behaviors at the DataManager level.

## Formula Columns

A column becomes a formula column when:

* `dataType` is set to `"formula"`
* `value` contains a formula expression

```javascript
columns: {
    TotalUnits: {
        dataType: "formula",
        value: "=[@UnitsInStock] + [@UnitsOnOrder]"
    }
}
```

Formula columns:

* Do not directly map to raw data fields
* Are evaluated per record
* Can reference other fields using structured references (`[@FieldName]`)

After evaluation, the computed result behaves like a normal column value.
Formula columns are recalculated when dependent fields change.

## Trigger Formulas

Trigger formulas allow a column to store a value while using a formula to compute or normalize it during specific events.

```javascript
columns: {
    Amount: {
        dataType: "number",
        trigger: {
            when: "onNewAndUpdate",
            formula: "=[@UnitPrice] * [@Quantity]",
            fields: "UnitPrice,Quantity"
        }
    }
}
```

A trigger definition includes:

* `when` — When the formula is executed
    * `"onNew"`
    * `"onNewAndUpdate"`
* `formula` — The formula expression to evaluate
* `fields` — The fields that cause the trigger to execute (required for `"onNewAndUpdate"`)

### Trigger Behavior Model

When a row is inserted:

* Triggers with `onNew` and `onNewAndUpdate` are evaluated.

When a row is updated:

* The trigger executes only if one of the watched fields changes.
* The evaluated result becomes the stored value of the column.

>type=note
> **Important:**
>
> * The evaluated value replaces the previous value.
> * Trigger formulas should not introduce circular dependencies.
> * If a trigger watches its own field, the new value participates in evaluation.

Trigger formulas differ from formula columns:

| Formula Column | Trigger Formula |
| -------------- | --------------- |
| Value is always computed | Value is stored |
| Recalculated dynamically | Executed only on specified events |
| No persistent override | Result persists after execution |

## lookup

The `lookup` property defines a column’s value domain.
It restricts or describes the set of allowed values for the column.
There are three supported forms:

### 1\. Static List

```javascript
columns: {
    Type: {
        lookup: ["Homework", "Quiz", "Exam"]
    }
}
```

The column value is limited to the provided list.

### 2\. Relationship Name

```javascript
columns: {
    WorkItemID: {
        lookup: "workItem"
    }
}
```

In this form:

* The column references a related table
* The relationship must be defined separately
* The lookup values are derived from the related table

### 3\. Lookup Options

```javascript
columns: {
    WorkItemID: {
        lookup: {
            name: "workItem",
            columns: ["ID", "Description"]
        }
    }
}
```

This form specifies:

* The related table
* Which fields participate in the lookup configuration

### Lookup Responsibility

`lookup` defines the column’s value source.
It:

* Describes the allowed value domain
* Enables relationship-aware behavior
* Serves as a prerequisite for cross-table views

The actual UI representation of lookup columns is handled by the view layer.

## cross (Schema Capability)

Columns defined with `lookup` can participate in cross views.
While cross configuration is typically defined at the view level, a column must:

* Have a valid lookup definition
* Participate in a defined relationship
* Have a primary key defined on the table

Cross presentation logic belongs to the view configuration.
At the schema level, the column only declares its relational capability.

## Advanced Responsibility

Advanced data settings introduce:

* Computed logic
* Event-driven recalculation
* Controlled value domains
* Relationship-aware modeling

They extend column behavior while remaining independent from presentation details.
Visual rendering and layout behaviors are configured in view-level settings.