TX Text Control .NET Server

Javascript: TableCollection.add Method

Method|Introduced in 28.0

Description

Adds a table at the current input position.

Syntax

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

Parameters

ParameterDescription
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.

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);