@felisdiligens/md-table-tools / Exports / Table
- addCell
- addColumn
- addRow
- columnCount
- getCell
- getCellByObjs
- getCells
- getCellsInColumn
- getCellsInRow
- getColumn
- getColumns
- getHeaderRows
- getNormalRows
- getRow
- getRows
- indexOfColumn
- indexOfRow
- mergeMultilineRows
- moveColumn
- moveRow
- removeColumn
- removeRow
- rowCount
- sanitize
- update
• new Table(rowNum?
, colNum?
)
Name | Type | Default value |
---|---|---|
rowNum |
number |
0 |
colNum |
number |
0 |
• afterTable: string
Text after the table
• beforeTable: string
Text before the table
• caption: TableCaption
• Private
cells: TableCell
[]
• Private
columns: TableColumn
[]
• Private
rows: TableRow
[]
▸ addCell(cell
): void
Adds the cell to the Table and the cell's respective TableRow and TableColumn.
(Be careful not to add a cell with row/column that already exist. Otherwise, the added cell will be overshadowed and not be used.)
Name | Type |
---|---|
cell |
TableCell |
void
▸ addColumn(index?
, col?
): TableColumn
Adds a TableColumn to the table.
Name | Type | Default value | Description |
---|---|---|---|
index |
number |
-1 |
Insert column at index. -1 means it's appended. |
col |
TableColumn |
undefined |
(optional) |
The added column.
▸ addRow(index?
, row?
): TableRow
Adds a TableRow to the table.
Name | Type | Default value | Description |
---|---|---|---|
index |
number |
-1 |
Insert row at index. -1 means it's appended. |
row |
TableRow |
undefined |
(optional) |
The added row.
▸ columnCount(): number
Returns the total amount of columns in the table.
number
▸ getCell(row
, column
): TableCell
Returns the cell at row and column. If the cell doesn't already exist, it will be created.
Name | Type | Description |
---|---|---|
row |
number | TableRow |
Either index or object reference. |
column |
number | TableColumn |
Either index or object reference. |
The cell at row and column.
▸ Private
getCellByObjs(rowObj
, columnObj
): TableCell
Returns the cell at row and column.
Name | Type |
---|---|
rowObj |
TableRow |
columnObj |
TableColumn |
▸ getCells(): TableCell
[]
Returns all cells in the table. Isn't necessarily sorted!
▸ getCellsInColumn(column
): TableCell
[]
Returns all cells within the given column. See also: ()
Name | Type | Description |
---|---|---|
column |
number | TableColumn |
Either index or object reference. |
▸ getCellsInRow(row
): TableCell
[]
Returns all cells within the given row. See also: ()
Name | Type | Description |
---|---|---|
row |
number | TableRow |
Either index or object reference. |
▸ getColumn(index
): TableColumn
Gets the column at index. Negative index counts back from the end. Returns undefined if out-of-bounds.
Name | Type |
---|---|
index |
number |
▸ getColumns(): TableColumn
[]
Returns all columns in the table, from left to right.
▸ getHeaderRows(): TableRow
[]
Returns a list of all rows that are headers.
TableRow
[]
▸ getNormalRows(): TableRow
[]
Returns a list of all rows that aren't headers.
TableRow
[]
▸ getRow(index
): TableRow
Gets the row at index. Negative index counts back from the end. Returns undefined if out-of-bounds.
Name | Type |
---|---|
index |
number |
▸ getRows(): TableRow
[]
Retruns all rows in the table, from top to bottom, including header rows.
TableRow
[]
▸ indexOfColumn(col
): number
Gets the index of the column. -1 if it hasn't been found.
Name | Type |
---|---|
col |
TableColumn |
number
▸ indexOfRow(row
): number
Gets the index of the row. -1 if it hasn't been found.
Name | Type |
---|---|
row |
TableRow |
number
▸ mergeMultilineRows(): Table
Merges multiline rows (from MultiMarkdown feature) into "normal" rows.
This will destroy MultiMarkdown formatting! Only use when rendering into different formats.
▸ moveColumn(col
, newIndex
): void
Moves the given column to the new index.
Throws
Can't move column outside of table.
Name | Type | Description |
---|---|---|
col |
number | TableColumn |
Either index or object reference. |
newIndex |
number |
The new index of the given column. |
void
▸ moveRow(row
, newIndex
): void
Moves the given row to the new index.
Throws
Can't move row outside of table.
Name | Type | Description |
---|---|---|
row |
number | TableRow |
Either index or object reference. |
newIndex |
number |
The new index of the given row. |
void
▸ removeColumn(col
): void
Removes the given column. Also removes all cells within the column.
Name | Type | Description |
---|---|---|
col |
number | TableColumn |
Either index or object reference. |
void
▸ removeRow(row
): void
Removes the given row. Also removes all cells within the row.
Name | Type | Description |
---|---|---|
row |
number | TableRow |
Either index or object reference. |
void
▸ rowCount(): number
Returns the total amount of rows in the table, including the header rows.
number
▸ Private
sanitize(): Table
Tries to find invalid configurations and sanitize them.
▸ update(): Table
→ Ensures that all table cells exist.
→ Updates indices and sorts the cells within rows and columns.
→ Tries to find invalid configurations and sanitize them.
Call this method after altering the table.