Constructor
new ve.dm.TableMatrix(tableNode)
#
A helper class that allows random access to the table cells and introduces place-holders for fields occupied by spanning cells, making it a non-sparse representation of the sparse HTML model. This is essential for the implementation of table manipulations, such as row insertions or deletions.
Example:
<table>
<tr><td rowspan=2>1</td><td colspan=2>2</td><td rowspan=2 colspan=2>3</td></tr>
<tr><td>4</td><td>5</td></tr>
</table>
Visually this table would look like:
-------------------
| 1 | 2 | 3 |
| |-------| |
| | 4 | 5 | |
-------------------
The HTML model is sparse which makes it hard to read but also difficult to work with programmatically. The corresponding TableCellMatrix would look like:
| C[1] | C[2] | P[2] | C[3] | P[3] |
| P[1] | C[4] | C[5] | P[3] | P[3] |
Where C[1] represents a Cell instance wrapping cell 1, and P[1] a PlaceHolder instance owned by that cell.
Parameters:
Name | Type | Description |
---|---|---|
tableNode |
ve.dm.TableNode | Reference to a table instance |
- Mixes in:
- Source:
A helper class that allows random access to the table cells and introduces place-holders for fields occupied by spanning cells, making it a non-sparse representation of the sparse HTML model.
Methods
findClosestCell(cell) → {ve.dm.TableMatrixCell|null
}
#
null
}
#
Finds the closest cell not being a placeholder for a given cell.
Parameters:
Name | Type | Description |
---|---|---|
cell |
ve.dm.TableMatrixCell | Table cell |
- Source:
Returns:
Closest cell
- Type
-
ve.dm.TableMatrixCell
|
null
getCell(row, col) → {ve.dm.TableMatrixCell|undefined
}
#
undefined
}
#
Retrieves a single cell.
Parameters:
Name | Type | Description |
---|---|---|
row |
number | Row index |
col |
number | Column index |
- Source:
Returns:
Cell, or undefined if out of bounds
- Type
-
ve.dm.TableMatrixCell
|
undefined
getColCount(row) → {number}
#
Get number of columns in a row
To get the number of columns in a table use #getMaxColCount
Parameters:
Name | Type | Description |
---|---|---|
row |
number | Row to count columns in |
- Source:
Returns:
Number of columns
- Type
- number
Get number of columns in a row
To get the number of columns in a table use #getMaxColCount
getColumn(col) → {Array.<ve.dm.TableMatrixCell>}
#
Retrieves all cells of a column with given index.
Parameters:
Name | Type | Description |
---|---|---|
col |
number | Column index |
- Source:
Returns:
The cells of a column
- Type
- Array.<ve.dm.TableMatrixCell>
getMatrix() → {Array.<Array.<ve.dm.TableMatrixCell>>}
#
Provides a reference to the internal cell matrix.
Note: this is primarily for internal use. Do not change the delivered matrix and do not store as it may be invalidated.
- Source:
Returns:
Table matrix
- Type
- Array.<Array.<ve.dm.TableMatrixCell>>
getMaxColCount() → {number}
#
Get the maximum number of columns in a table
This is required because in sparse tables the column count is variable.
- Source:
Returns:
Number of columns
- Type
- number
Get the maximum number of columns in a table
This is required because in sparse tables the column count is variable.
getRow(row) → {Array.<ve.dm.TableMatrixCell>}
#
Retrieves all cells of a row with given index.
Parameters:
Name | Type | Description |
---|---|---|
row |
number | Row index |
- Source:
Returns:
The cells of a row
- Type
- Array.<ve.dm.TableMatrixCell>
getRowCount() → {number}
#
Get number of rows in the table
- Source:
Returns:
Number of rows
- Type
- number
getRowNode(row) → {ve.dm.TableRowNode|undefined
}
#
undefined
}
#
Retrieves the row node of a row with given index.
It is possible for bad tables to be constructed with rowspans that exceed the last actual row node. In these cases, the number of rows in the table matrix will exceed the number of row nodes, so users should expected getRowNode to sometimes return undefined. (T191858)
Parameters:
Name | Type | Description |
---|---|---|
row |
number | Row index |
- Source:
Returns:
Node at given index, if found
- Type
-
ve.dm.TableRowNode
|
undefined
getRowNodes() → {Array.<ve.dm.TableRowNode>}
#
Provides a reference to the internal array of row nodes.
Note: this is primarily for internal use. Do not change the delivered array and do not store it as it may be invalidated.
- Source:
Returns:
Table row nodes
- Type
- Array.<ve.dm.TableRowNode>
invalidate()
#
Invalidates the matrix structure.
This is called by ve.dm
.TableNode on structural changes.
- Source:
Fires:
lookupCell(cellNode) → {ve.dm.TableMatrixCell|null
}
#
null
}
#
Look up the matrix cell for a given cell node.
Parameters:
Name | Type | Description |
---|---|---|
cellNode |
ve.dm.TableCellNode | Cell node |
- Source:
Returns:
The cell or null if not found
- Type
-
ve.dm.TableMatrixCell
|
null
update()
#
Recreates the matrix structure.
- Source:
Events
structureChange()
#
- Source: