# Remote Column CRUD

## Content

In addition to row data synchronization, a remote table can synchronize column definitions with the server.
This enables:

* Dynamic column creation
* Column property updates
* Column removal
* Centralized schema management

Column operations require corresponding remote endpoints.

## Enabling Remote Column Management

To manage columns remotely, configure:

* `getColumns`
* `addColumn`
* `updateColumn`
* `removeColumn`

Example:

```javascript
const orders = dataManager.addTable("orders", {
    remote: {
        read: {
            url: "http://localhost:3000/api/orders",
            method: "GET"
        },
        getColumns: {
            url: "http://localhost:3000/api/orders/columns",
            method: "GET"
        },
        addColumn: {
            url: "http://localhost:3000/api/orders/columns",
            method: "POST"
        },
        updateColumn: {
            url: "http://localhost:3000/api/orders/columns",
            method: "PUT"
        },
        removeColumn: {
            url: "http://localhost:3000/api/orders/columns",
            method: "DELETE"
        }
    },
    autoSync: true
});

orders.fetch();
```

## getColumns

`getColumns` retrieves the column definitions from the server.
Typical use:

* Initialize schema from remote storage
* Ensure client and server column structures match

The response should return a column definition list compatible with DataManager.
Column structure details are described in the API reference.

## addColumn

When a new column is defined in the TableSheet, a remote request is sent.
In single sync mode:

* The request is sent immediately.
* The server persists the new column definition.

In batch mode:

* The change is stored locally.
* The column change is sent during `submitChanges()`.

## updateColumn

When column properties are modified:

* Caption
* Data type
* Default value
* Primary key flag

The corresponding remote endpoint is invoked.
In single sync mode:

* Sent immediately.

In batch mode:

* Stored and submitted together with other changes.

## removeColumn

When a column is removed:

* The server must delete the corresponding column definition.
* Associated data behavior depends on server implementation.

In single sync mode:

* Immediate request.

In batch mode:

* Included in the batch payload.

## Batch Behavior for Column Changes

If `batch: true` is enabled:

* Row changes and column changes are combined.
* `submitChanges()` sends all modifications together.
* The server should treat the batch as atomic if possible.

Example submission flow:

```javascript
orders.submitChanges();
```

To cancel pending changes:

```javascript
orders.cancelChanges();
```

Batch payload may include:

* addColumn
* updateColumn
* removeColumn
* insert
* update
* delete

Exact request structure is defined in the API reference.

## Custom Column Handlers

Instead of URL configurations, operations can be defined as functions:

```javascript
const orders = dataManager.addTable("orders", {
    remote: {
        read: function () {
            return Promise.resolve([...]);
        },
        addColumn: function (change) {
            return Promise.resolve(change);
        }
    },
    autoSync: true
});
```

This allows:

* Custom transport logic
* Middleware integration
* Mock implementations

>type=note
> Note:
> Function handlers cannot be serialized during export.

## Important Constraints

Remote column synchronization requires:

* Consistent column identifiers (`value`)
* Server-side support for column persistence
* Proper handling of data-type changes

If server validation fails:

* The operation should return an error
* The table state will reflect the failure

Server-side schema enforcement is application-specific.