# table/utils/structure

module

<a id="functions">

## Functions

<a id="function-adjustLastColumnIndex">

### `adjustLastColumnIndex( table, dimensions = { dimensions.firstColumn, dimensions.firstRow, dimensions.lastColumn, dimensions.lastRow } ) → number` _(internal)_

Returns adjusted last column index if selection covers part of a column with empty slots (spanned by other cells). The `dimensions.lastColumn` is equal to last column index but selection might be bigger.

This happens _only_ on rectangular selection so we analyze a case like this:

```
  0   1   2   3
+---+---+---+---+
| a             |
+---+---+---+---+
| b | c | d     |
+---+---+---+---+
| e     | f     |
+---+---+---+---+
| g | h         |
+---+---+---+---+
          ^
         last column, each cell has colspan = 2, so we need to return 3, not 2
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L580)

#### Parameters

* `table: ModelElement`

* `dimensions: object`

  Properties

  * `dimensions.firstColumn: number`
  * `dimensions.firstRow: number`
  * `dimensions.lastColumn: number`
  * `dimensions.lastRow: number`

#### Returns

* `number`

  Adjusted last column index.

<a id="function-adjustLastRowIndex">

### `adjustLastRowIndex( table, dimensions = { dimensions.firstColumn, dimensions.firstRow, dimensions.lastColumn, dimensions.lastRow } ) → number` _(internal)_

Returns adjusted last row index if selection covers part of a row with empty slots (spanned by other cells). The `dimensions.lastRow` is equal to last row index but selection might be bigger.

This happens _only_ on rectangular selection so we analyze a case like this:

```
   +---+---+---+---+
 0 | a | b | c | d |
   +   +   +---+---+
 1 |   | e | f | g |
   +   +---+   +---+
 2 |   | h |   | i | <- last row, each cell has rowspan = 2,
   +   +   +   +   +    so we need to return 3, not 2
 3 |   |   |   |   |
   +---+---+---+---+
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L531)

#### Parameters

* `table: ModelElement`

* `dimensions: object`

  Properties

  * `dimensions.firstColumn: number`
  * `dimensions.firstRow: number`
  * `dimensions.lastColumn: number`
  * `dimensions.lastRow: number`

#### Returns

* `number`

  Adjusted last row index.

<a id="function-cropTableToDimensions">

### `cropTableToDimensions( sourceTable, cropDimensions = { cropDimensions.endColumn, cropDimensions.endRow, cropDimensions.startColumn, cropDimensions.startRow }, writer ) → ModelElement` _(internal)_

Returns a cropped table according to given dimensions.

To return a cropped table that starts at first row and first column and end in third row and column:

```typescript
const croppedTable = cropTableToDimensions( table, {
  startRow: 1,
  endRow: 3,
  startColumn: 1,
  endColumn: 3
}, writer );
```

Calling the code above for the table below:

```
   0   1   2   3   4                      0   1   2
 ┌───┬───┬───┬───┬───┐
```

0 │ a │ b │ c │ d │ e │ ├───┴───┤ ├───┴───┤ ┌───┬───┬───┐ 1 │ f │ │ g │ │ │ │ g │ 0 ├───┬───┴───┼───┬───┤ will return: ├───┴───┼───┤ 2 │ h │ i │ j │ k │ │ i │ j │ 1 ├───┤ ├───┤ │ │ ├───┤ 3 │ l │ │ m │ │ │ │ m │ 2 ├───┼───┬───┤ ├───┤ └───────┴───┘ 4 │ n │ o │ p │ │ q │ └───┴───┴───┴───┴───┘

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L52)

#### Parameters

* `sourceTable: ModelElement`

* `cropDimensions: object`

  Properties

  * `cropDimensions.endColumn: number`
  * `cropDimensions.endRow: number`
  * `cropDimensions.startColumn: number`
  * `cropDimensions.startRow: number`

* `writer: ModelWriter`

#### Returns

* `ModelElement`

<a id="function-getHorizontallyOverlappingCells">

### `getHorizontallyOverlappingCells( table, overlapColumn ) → Array<TableSlot>` _(internal)_

Returns slot info of cells that starts before and overlaps a given column.

In a table below, passing `overlapColumn = 3`

0 1 2 3 4 ┌───────┬───────┬───┐ │ a │ b │ c │ │───┬───┴───────┼───┤ │ d │ e │ f │ ├───┼───┬───────┴───┤ │ g │ h │ i │ ├───┼───┼───┬───────┤ │ j │ k │ l │ m │ ├───┼───┴───┼───┬───┤ │ n │ o │ p │ q │ └───┴───────┴───┴───┘ ^ Overlap column to check

will return slot info for cells: "b", "e", "i".

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L237)

#### Parameters

* `table: ModelElement`

  The table to check.

* `overlapColumn: number`

  The index of the column to check.

#### Returns

* `Array<TableSlot>`

<a id="function-getVerticallyOverlappingCells">

### `getVerticallyOverlappingCells( table, overlapRow, startRow ) → Array<TableSlot>` _(internal)_

Returns slot info of cells that starts above and overlaps a given row.

In a table below, passing `overlapRow = 3`

```
┌───┬───┬───┬───┬───┐
```

0 │ a │ b │ c │ d │ e │ │ ├───┼───┼───┼───┤ 1 │ │ f │ g │ h │ i │ ├───┤ ├───┼───┤ │ 2 │ j │ │ k │ l │ │ │ │ │ ├───┼───┤ 3 │ │ │ │ m │ n │ <- overlap row to check ├───┼───┤ │ ├───│ 4 │ o │ p │ │ │ q │ └───┴───┴───┴───┴───┘

will return slot info for cells: "j", "f", "k".

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L142)

#### Parameters

* `table: ModelElement`

  The table to check.

* `overlapRow: number`

  The index of the row to check.

* `startRow: number`

  row to start analysis. Use it when it is known that the cells above that row will not overlap. Default value is 0.

  Defaults to `0`

#### Returns

* `Array<TableSlot>`

<a id="function-getViewTableFromWrapper">

### `getViewTableFromWrapper( wrapperView ) → ViewElement | undefined`

Get view `<table>` element from the wrapper.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L610)

#### Parameters

* `wrapperView: ViewElement`

#### Returns

* `ViewElement | undefined`

<a id="function-removeEmptyColumns">

### `removeEmptyColumns( table, tableUtils ) → boolean` _(internal)_

Removes columns that have no cells anchored.

In table below:

```
+----+----+----+----+----+----+----+
| 00 | 01      | 03 | 04      | 06 |
+----+----+----+----+         +----+
| 10 | 11      | 13 |         | 16 |
+----+----+----+----+----+----+----+
| 20 | 21      | 23 | 24      | 26 |
+----+----+----+----+----+----+----+
             ^--- empty ---^
```

Will remove columns 2 and 5.

**Note:** This is a low-level helper method for clearing invalid model state when doing table modifications. To remove a column from a table use [`TableUtils.removeColumns()`](module_table_tableutils-TableUtils.md#function-removeColumns).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L400)

#### Parameters

* `table: ModelElement`
* `tableUtils: TableUtils`

#### Returns

* `boolean`

  True if removed some columns.

<a id="function-removeEmptyRows">

### `removeEmptyRows( table, tableUtils ) → boolean` _(internal)_

Removes rows that have no cells anchored.

In table below:

```
+----+----+----+
| 00 | 01 | 02 |
+----+----+----+
| 10 | 11 | 12 |
+    +    +    +
|    |    |    | <-- empty
+----+----+----+
| 30 | 31 | 32 |
+----+----+----+
| 40      | 42 |
+         +    +
|         |    | <-- empty
+----+----+----+
| 60 | 61 | 62 |
+----+----+----+
```

Will remove rows 2 and 5.

**Note:** This is a low-level helper method for clearing invalid model state when doing table modifications. To remove a row from a table use [`TableUtils.removeRows()`](module_table_tableutils-TableUtils.md#function-removeRows).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L454)

#### Parameters

* `table: ModelElement`
* `tableUtils: TableUtils`

#### Returns

* `boolean`

  True if removed some rows.

<a id="function-removeEmptyRowsColumns">

### `removeEmptyRowsColumns( table, tableUtils ) → void` _(internal)_

Removes rows and columns that have no cells anchored.

In table below:

```
+----+----+----+----+
| 00      | 02      |
+----+----+         +
| 10      |         |
+----+----+----+----+
| 20      | 22 | 23 |
+         +    +    +
|         |    |    | <-- empty row
+----+----+----+----+
        ^--- empty column
```

Will remove row 3 and column 1.

**Note:** This is a low-level helper method for clearing invalid model state when doing table modifications. To remove a rows from a table use [`TableUtils.removeRows()`](module_table_tableutils-TableUtils.md#function-removeRows) and [`TableUtils.removeColumns()`](module_table_tableutils-TableUtils.md#function-removeColumns) to remove a column.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L503)

#### Parameters

* `table: ModelElement`
* `tableUtils: TableUtils`

#### Returns

* `void`

<a id="function-splitHorizontally">

### `splitHorizontally( tableCell, splitRow, writer ) → ModelElement | null` _(internal)_

Splits the table cell horizontally.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L165)

#### Parameters

* `tableCell: ModelElement`
* `splitRow: number`
* `writer: ModelWriter`

#### Returns

* `ModelElement | null`

  Created table cell, if any were created.

<a id="function-splitVertically">

### `splitVertically( tableCell, columnIndex, splitColumn, writer ) → ModelElement` _(internal)_

Splits the table cell vertically.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L262)

#### Parameters

* `tableCell: ModelElement`

* `columnIndex: number`

  The table cell column index.

* `splitColumn: number`

  The index of column to split cell on.

* `writer: ModelWriter`

#### Returns

* `ModelElement`

  Created table cell.

<a id="function-trimTableCellIfNeeded">

### `trimTableCellIfNeeded( tableCell, cellRow, cellColumn, limitRow, limitColumn, writer ) → void` _(internal)_

Adjusts table cell dimensions to not exceed limit row and column.

If table cell width (or height) covers a column (or row) that is after a limit column (or row) this method will trim "colspan" (or "rowspan") attribute so the table cell will fit in a defined limits.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/utils/structure.ts#L295)

#### Parameters

* `tableCell: ModelElement`
* `cellRow: number`
* `cellColumn: number`
* `limitRow: number`
* `limitColumn: number`
* `writer: ModelWriter`

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
