# Javascript: Table.mergeCells Method

> Merges all selected table cells in this table. {@link Table#getCanMergeCells} can be used to determine, if table cells can be merged or not.

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

---

### Description

Merges all selected table cells in this table. {@link Table#getCanMergeCells} can be used to determine, if table cells can be merged or not.

### Syntax

```javascript
<void> Table.mergeCells([<RequestBooleanCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| callback | Optional. Receives whether the merge was succesful. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `Table.mergeCells` in a practical document-editing workflow. It merges all selected table cells in this table. {@link Table#getCanMergeCells} can be used to determine, if table cells can be merged or not.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const tables = mainText.tables;
    tables.getItem(function(table) {
        if (!table) {
            console.warn("No table is available at the current input position.");
            return;
        }
    
        table.mergeCells(
            function(result) {
                if (result) {
                    console.log("merge cells is available.");
                } else {
                    console.warn("merge cells is not available in the current document state.");
                }
            },
            onTxError
        );
    }, onTxError);
}, onTxError);
```

---

## Nearby

- **Previous:** [Javascript: Table.getOuterTable Method](https://docs.textcontrol.com/ds-server/reference/javascript/table/getoutertable-method/llms-full.txt)
- **Next:** [Javascript: Table.nestedTables Property](https://docs.textcontrol.com/ds-server/reference/javascript/table/nestedtables-property/llms-full.txt)
