# Defining Columns

## Content

A table schema defines how raw data is interpreted and managed inside DataManager.
Within a schema, columns are the core modeling units.
Each column describes how a field in a record behaves inside a table.
Columns are not UI elements.
They are data modeling definitions that determine identity, type, behavior, and presentation metadata.

## From Records to Columns

When data is loaded into a table, each object in the data source becomes a record (row).

```javascript
const table = dataManager.addTable("orders", {
    data: [
        { id: 1, price: 10, quantity: 2 }
    ],
    schema: {
        columns: {
            id: { dataType: "number", isPrimaryKey: true },
            price: { dataType: "number" },
            quantity: { dataType: "number" },
            total: {
                dataType: "formula",
                value: "=[@price] * [@quantity]"
            }
        }
    }
});
```

In this example:

* `id` defines record identity.
* `price` and `quantity` define typed fields.
* `total` is a computed column derived from other fields.

Without column definitions, fields are interpreted using default behavior.
By defining columns explicitly, you control how data is structured and managed.

## What a Column Definition Can Control

A column definition can specify:

* How a field maps to raw data
* How its value is parsed and typed
* Whether it uniquely identifies a record
* Whether it is computed or event-driven
* Validation and indexing behavior
* Default presentation metadata

To keep responsibilities clear, column configuration is organized into the following categories:

### [Core Structure Settings](/spreadjs/docs/features/data-manager/schema/defining-columns/core-structure-settings)

Define identity and structural mapping.
Examples include:

* Column name and data mapping
* `dataType`
* `isPrimaryKey`
* Formula-based value definitions

These settings determine how records are structurally interpreted.

### [Data Behavior Settings](/spreadjs/docs/features/data-manager/schema/defining-columns/data-behavior-settings)

Control how column values behave after parsing.
Examples include:

* Required and readonly rules
* Default values
* Parsing patterns
* Indexing
* Display substitutions for null and empty values

These settings influence validation, normalization, and performance.

### [Advanced Data Settings](/spreadjs/docs/features/data-manager/schema/defining-columns/advanced-data-settings)

Enable dynamic and relational behaviors.
Examples include:

* Formula columns
* Trigger formulas
* Lookup definitions
* Relationship-aware capabilities

These settings introduce computation and controlled value domains.

### [Style & UI Metadata](/spreadjs/docs/features/data-manager/schema/defining-columns/style---ui-metadata)

Define default presentation behavior when rendered by a view.
Examples include:

* Caption and width
* Cell styles and header styles
* Conditional formatting
* Validation rules
* Interaction controls

These settings do not modify stored data.
They provide baseline metadata that views can consume and override.

## Responsibility Boundary

Column definitions belong to the table schema.
They:

* Model how data behaves inside DataManager
* Remain independent from specific UI implementations

[Views](/spreadjs/docs/features/data-manager/view) consume column metadata to render data.
View-level configuration can override presentation-related settings without altering the schema.
This separation ensures that data modeling and presentation remain decoupled within the documentation system and the product architecture.