# Javascript: TableCollection.add Method

> Adds a table at the current input position.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: TableCollection.add Method
- **534 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/tablecollection/add-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/tablecollection/add-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/tablecollection/add-method/llms-full.txt

---

### Description

Adds a table at the current input position.

### Syntax

```javascript
<void> TableCollection.add(<number> rows, <number> columns, [<number> id], [<RequestBooleanCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| rows | Specifies the number of rows the table consists of. |
| columns | Specifies the number of columns the table consists of. |
| id | Optional. The table's identifier. |
| callback | Optional. Receives whether the table could be added. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example inserts an invoice table, resolves it by ID, and adds descriptive text for accessibility.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    mainText.tables.add(3, 4, 25, function(added) {
        if (!added) {
            console.warn("A table cannot be inserted at the current input position.");
            return;
        }

        mainText.tables.getItem(function(table) {
            table.setDescriptiveText("Invoice line items", function() {
                console.log("Invoice table added.");
            }, onTxError);
        }, onTxError, 25);
    }, onTxError);
}, onTxError);
```

---

## Nearby

- **Previous:** [TableCollection Object](https://docs.textcontrol.com/ds-server/reference/javascript/tablecollection/llms-full.txt)
- **Next:** [Javascript: TableCollection.getCanAdd Method](https://docs.textcontrol.com/ds-server/reference/javascript/tablecollection/getcanadd-method/llms-full.txt)
