Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Table Class

Defines a table in the document.

#Declaration

TypeScript
export class Table extends TableElementBase

#Remarks

richEdit.beginUpdate();
richEdit.history.beginTransaction();
var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var columnCount = 5;
var rowCount = 5;
var table = subDocument.tables.create(position, columnCount, rowCount);
for (var rowInd = 0, row; row = table.rows.getByIndex(rowInd); rowInd++) {
    for (var cellInd = 0, cell; cell = row.cells.getByIndex(cellInd); cellInd++) {
        subDocument.insertText(cell.interval.start, "Row[" + rowInd + "].Cell[" + cellInd + "]");
    }
}
richEdit.history.endTransaction();
richEdit.endUpdate();

#Properties

#autoFit Property

Specifies whether the table automatically adjusts its width to fit content.

#Declaration

TypeScript
get autoFit(): boolean
set autoFit(value: boolean)

#Property Value

Type Description
boolean

true if the table automatically adjusts its width to fit content; otherwise, false.

#Remarks

A table can automatically adjust its width to fit content. Use the autoFit property to identify whether size adjustment is enabled.

#backgroundColor Property

Specifies the table’s background color.

#Declaration

TypeScript
get backgroundColor(): string
set backgroundColor(value: string)

#Property Value

Type Description
string

The table’s background color.

#Remarks

The backgroundColor property allows you to obtain and change the table’s background color.

Note

A cell’s background (TableCell.backgroundColor) overlaps the table’s background (Table.backgroundColor).

#borders Property

Specifies the table’s border settings.

#Declaration

TypeScript
get borders(): TableBorders
set borders(value: ITableBorders)

#Property Value

Type Description
TableBorders

Table border settings.

#Remarks

Specify the borders property to configure a table’s border settings.

#cellMargins Property

Specifies margin settings of all cells in the table.

#Declaration

TypeScript
get cellMargins(): Margins
set cellMargins(value: IMargins)

#Property Value

Type Description
Margins

An object that contains margin settings.

#Remarks

Use the cellMargins property to access and customize the margins of all table cells.

Note

A cell’s margins property takes priority over the table’s cellMargins property.

#contentHorizontalAlignment Property

Specifies the horizontal alignment of table content.

#Declaration

TypeScript
get contentHorizontalAlignment(): TableContentHorizontalAlignment | null
set contentHorizontalAlignment(value: TableContentHorizontalAlignment)

#Property Value

Type Description
TableContentHorizontalAlignment

An enumeration value.

#Remarks

Use the contentHorizontalAlignment property to horizontally align content in all table cells.

Note

A cell’s contentHorizontalAlignment property takes priority over the table’s contentHorizontalAlignment property.

#contentVerticalAlignment Property

Specifies the vertical alignment of table content.

#Declaration

TypeScript
get contentVerticalAlignment(): TableContentVerticalAlignment | null
set contentVerticalAlignment(value: TableContentVerticalAlignment)

#Property Value

Type Description
TableContentVerticalAlignment

An enumeration value.

#Remarks

Use the contentHorizontalAlignment property to horizontally align content in all table cells.

Note

A cell’s contentHorizontalAlignment property takes priority over the table’s contentHorizontalAlignment property.

#index Property

Gets an index of the table.

#Declaration

TypeScript
get index(): number

#Property Value

Type Description
number

The table’s index.

#Remarks

Use the index to access the corresponding table by the TableCollection.getByIndex method.

#interval Property

Gets the text buffer interval occupied by the current table element.

#Declaration

TypeScript
get interval(): Interval

#Property Value

Type Description
Interval

An object that contains the interval settings.

#parentCell Property

Returns the cell that contains the current table.

#Declaration

TypeScript
get parentCell(): TableCell | null

#Property Value

Type Description
TableCell

The cell that contains the current table; null if the table is not nested.

#rows Property

Provides access to a collection of table rows.

#Declaration

TypeScript
get rows(): TableRowCollection

#Property Value

Type Description
TableRowCollection

An array of TableRow objects that store information about individual table rows.

#styleName Property

Specifies the table style name.

#Declaration

TypeScript
get styleName(): string
set styleName(value: string)

#Property Value

Type Description
string

The table style name.

#Remarks

Use the styleName property to customize table appearance. Specify the tableStyleOptions property to apply/remove special formatting from the first, last, and odd columns and rows.

Note

Style options do not affect table appearance if the Normal Table or Grid Table Light style is applied to the table.

#tableStyleOptions Property

Specifies style options applied to the table.

#Declaration

TypeScript
get tableStyleOptions(): TableStyleOptions
set tableStyleOptions(value: TableStyleOptions)

#Property Value

Type Description
TableStyleOptions

Table style options.

#Remarks

Specify the tableStyleOptions property to apply/remove special formatting from the first, last, and odd columns and rows.

Note

Style options do not affect table appearance if the Normal Table or Grid Table Light style is applied to the table.

#width Property

Specifies the table’s width settings.

#Declaration

TypeScript
get width(): TableWidth
set width(value: TableWidth)

#Property Value

Type Description
TableWidth

An object that contains width settings.

#Remarks

Use the Table.width or TableCell.width property to specify the table or cell width.

#Methods

#delete Method

Deletes the current table.

#Declaration

TypeScript
delete(): void

#Remarks

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var tables = subDocument.tables.find(position);
for(var i = tables.length - 1, table; table = tables[i]; i--)
    table.delete();

#mergeCells(startPosition, endPosition) Method

Merges all cells in the specified range.

#Declaration

TypeScript
mergeCells(
    startPosition: TableCellPosition,
    endPosition: TableCellPosition
): void

#Parameters

Name Type Description
startPosition TableCellPosition

The position of the first cell in the range.

endPosition TableCellPosition

The position of the last cell in the range.

#Remarks

A TableCellPosition object stores a cell’s position in the table. Pass two cell positions to the mergeCells method to merge all cells in the specified range. The resulting cell has the same appearance settings as the first cell in the range.

The following code snippet merges 6 cells:

js
const subDocument = richEdit.selection.activeSubDocument;
const table = subDocument.tables.getByIndex(0);
const startCell = { rowIndex: 0, cellIndex: 0 };
const endCell = { rowIndex: 2, cellIndex: 1 };
table.mergeCells(startCell, endCell);