The type of the row data.
The identifier for one of the areas: header, body, footer. This property determines which area of the table this model represents.
// Creating an area model for the header
const headerModel = new AreaModel();
headerModel.areaIdent = "header";
// Checking which area a model represents
if (areaModel.areaIdent === "body") {
// This is a body area model
}
Protected cellProtected columnColumns without an own editable are editable (Excel-style editing, EditingOptionsIf.defaultEditable; set by
the table). Row number, checkbox and group columns stay read only.
1.1.99
Protected Readonly propertiesA model and controller for row checkbox selection. This property allows the area to support row selection via checkboxes.
// Creating a checkbox model for row selection
import { CheckboxModel } from "@guiexpert/table";
const bodyModel = new AreaModel();
bodyModel.areaIdent = "body";
bodyModel.rowSelectionModel = new CheckboxModel();
// Later, check if a row is selected
const isSelected = bodyModel.isRowChecked(5);
Readonly rowsProtected yProtected addProtected apply„Show values as“ of one tree row: percentages of the column total relate to the (filtered) leaf rows,
percentOfParentTotal, runningTotal, differenceFromPrevious and rank to the displayed siblings.
Protected arrayRow drag: true if the rows can be moved to the target – no filter hides a displayed row, and the target is none of
the dragged rows and no descendant of them (no cycle). "before" / "after" = sibling of the target row,
"inside" = last child.
display indices of the dragged rows
the drop target
true if moveRows would move them
const treeModel = tableModel.getBodyModel() as AreaModelTree<OrderNode>;
treeModel.canMoveRows([0], { rowIndex: 1, position: "inside" }); // false if row 1 is a child of row 0
1.1.95
Changes the order of columns by moving a column from one position to another. This method is called when the user drags a column to a new position.
The index of the column to move
The index where the column should be moved to
// Move the second column (index 1) to the fourth position (index 3)
areaModel.changeColumnOrder(1, 3);
// Implementation example
changeColumnOrder(sourceColumnIndex: number, targetColumnIndex: number): void {
// Move the column in the internal data structure
this.arrayMove(this.columns, sourceColumnIndex, targetColumnIndex);
// Update any dependent data structures
this.arrayMove(this.cellRenderers, sourceColumnIndex, targetColumnIndex);
}
Sorts the rows of every level (children stay below their parent) and keeps the active filter. The first sort
item is the primary key, the following ones break ties. The rows array and the children arrays are reordered
in place, so the order survives expanding, collapsing and filtering. Sort state "" keeps the current order.
primary key first; an empty list does nothing
true if the rows were sorted, false for an empty list
tableModel.getBodyModel().doSort([new SortItem(1, "desc")]);
tableApi.repaint();
Filters the tree; the function is remembered and applied again on every expand/collapse (recalcVisibleTreeRows), toggleExpandCollapseAll and doSort.
The function is called once for every tree row in depth-first order – also for rows below collapsed
parents – with the tree row (not your object: use row.data), the index of the row in
this depth-first list and the list itself. Shown are the rows that match or have a matching descendant
(row.keep = true) and whose parents are all expanded. A match below a collapsed node therefore keeps the
collapsed node visible. Usually called by tableApi.externalFilterChanged() with
tableOptions.externalFilterFunction.
returns a truthy value for the rows to show
const treeModel = tableModel.getBodyModel() as AreaModelTree<OrderNode>;
treeModel.externalFilterChanged((row: TreeRowIf<OrderNode>) => row.data.total > 1000);
tableApi.repaintHard();
// remove the filter
treeModel.externalFilterChanged(() => true);
Protected genericProtected getThe rows of column aggregates in formulas (SUM([total])): the filtered row objects.
Protected getThe renderer of a „Show values as“ column without an own renderer: the text of getTextValueAt.
Protected getA „Show values as“ column without an own body renderer shows the formatted text.
Returns the column span value for the cell at the specified row and column indices. A colspan value of N means the cell spans N columns horizontally. Values less than 2 are ignored (no spanning).
The index of the row
The index of the column
The colspan value (number of columns the cell spans)
// Check if a cell spans multiple columns
const colspan = headerAreaModel.getColspanAt(0, 0);
if (colspan > 1) {
console.log(`This header cell spans ${colspan} columns`);
}
// Implementation example for a model with column spanning
getColspanAt(rowIndex: number, columnIndex: number): number {
// Special case: first row, first column spans 3 columns
if (rowIndex === 0 && columnIndex === 0) return 3;
// No spanning for other cells
return 1;
}
Returns an array of CSS class names to apply to the cell at the specified row and column indices. This method allows for custom styling of individual cells.
The index of the row
The index of the column
An array of CSS class names
// Apply custom classes to cells
const classes = bodyAreaModel.getCustomClassesAt(1, 2);
console.log(`Cell classes: ${classes.join(', ')}`);
// Implementation example with conditional styling
getCustomClassesAt(rowIndex: number, columnIndex: number): string[] {
const classes: string[] = [];
// Add classes based on row index
if (rowIndex % 2 === 0) {
classes.push('even-row');
} else {
classes.push('odd-row');
}
// Add classes based on cell value
const value = this.getValueAt(rowIndex, columnIndex);
if (typeof value === 'number' && value < 0) {
classes.push('negative-value');
}
// Add classes for selected rows
if (this.isRowChecked(rowIndex)) {
classes.push('selected-row');
}
return classes;
}
Returns an object containing CSS style properties to apply to the cell at the specified row and column indices. This method allows for inline styling of individual cells.
The index of the row
The index of the column
An object with CSS style properties, or undefined if no custom styles
// Apply custom styles to cells
const styles = bodyAreaModel.getCustomStyleAt(1, 2);
console.log('Cell styles:', styles);
// Implementation example with conditional styling
getCustomStyleAt(rowIndex: number, columnIndex: number): { [key: string]: string } | undefined {
// Apply background color based on value
const value = this.getValueAt(rowIndex, columnIndex);
if (typeof value === 'number') {
// Color gradient based on value
if (value < 0) {
return { 'background-color': `rgba(255, 0, 0, ${Math.min(Math.abs(value) / 100, 0.5)})` };
} else if (value > 0) {
return { 'background-color': `rgba(0, 255, 0, ${Math.min(value / 100, 0.5)})` };
}
}
return undefined; // No custom styles
}
The displayed children of a row (in display order): all children, with an active filter only those that match
(or have a matching descendant). They are on screen if the row is expanded.
Used for the screen reader attributes aria-setsize / aria-posinset of tree rows.
a tree row of this model
the displayed children (empty for a leaf)
const treeModel = tableModel.getBodyModel() as AreaModelTree<OrderNode>;
const shown = treeModel.getDisplayedChildren(treeModel.rows[0]).length;
1.1.91
The leaves (rows without children) of the whole tree, depth-first in the current order – independent of the expanded state. Used for totals: collapsing a node does not change them, and parent rows are not counted twice.
Optional filtered: boolean = trueonly the leaves the active filter keeps (externalFilterChanged); false: all
a new array
const treeModel = tableModel.getBodyModel() as AreaModelTree<OrderNode>;
const total = aggregate(treeModel.getLeafRows(), row => row.data.total, "sum");
1.1.94
Returns the maximum colspan value that can occur in this area model. This value is used to optimize rendering performance.
The maximum possible colspan value in this area
// Get the maximum colspan for optimization
const maxColspan = headerAreaModel.getMaxColspan();
// Implementation example
getMaxColspan(): number {
// If the model has no colspans, return 0 for optimization
return 0;
// If the model has colspans, return the maximum possible value
// return 3; // If some cells span up to 3 columns
}
Returns the maximum rowspan value that can occur in this area model. This value is used to optimize rendering performance.
The maximum possible rowspan value in this area
// Get the maximum rowspan for optimization
const maxRowspan = bodyAreaModel.getMaxRowspan();
// Implementation example
getMaxRowspan(): number {
// If the model has no rowspans, return 0 for optimization
return 0;
// If the model has rowspans, return the maximum possible value
// return 2; // If some cells span up to 2 rows
}
Protected getThe value of a tree row for a property – before „Show values as“: the computed value of a calculated column,
otherwise the property (path) of row.data. Subclasses (row groups) return their aggregates for group rows.
the tree row
the property of the column
the raw value
1.1.95
Returns the row object at the specified index. This method provides access to the underlying data structure.
The index of the row
The row object
// Get a row object
const row = bodyAreaModel.getRowByIndex(1);
console.log('Row data:', row);
// Implementation example for an array-based model
getRowByIndex(rowIndex: number): any {
if (rowIndex < 0 || rowIndex >= this.data.length) return undefined;
return this.data[rowIndex];
}
Returns the number of rows in this area. This is a fundamental method that determines the vertical size of the area.
The number of rows in the area
// Get the number of rows in the body area
const rowCount = bodyAreaModel.getRowCount();
console.log(`The body has ${rowCount} rows`);
// Implementation example for an array-based model
getRowCount(): number {
return this.data.length;
}
Returns the height of the row at the specified index, in pixels. This method allows for variable row heights in the table.
The index of the row
The height of the row in pixels
// Get the height of a row
const height = bodyAreaModel.getRowHeight(1);
console.log(`Row 1 height: ${height}px`);
// Implementation example with fixed row height
getRowHeight(rowIndex: number): number {
return this.defaultRowHeight; // e.g., 30px
}
// Implementation example with variable row heights
getRowHeight(rowIndex: number): number {
// First row is taller
if (rowIndex === 0) return 50;
// Rows with more content are taller
const row = this.getRowByIndex(rowIndex);
if (row && row.hasLongContent) return 60;
// Default height for other rows
return 30;
}
The value of a column for a row object – the computed value of a calculated column, otherwise the property
(path). A TreeRow is unwrapped. The table API offers it as TableApi.getRowValue.
a row object (or TreeRow)
the property of the column
the value
const body = tableModel.getBodyModel() as AreaModelObjectArray<Item>;
body.getRowValue({ price: 25, quantity: 10 }, "total"); // 250
1.1.95
Returns the row span value for the cell at the specified row and column indices. A rowspan value of N means the cell spans N rows vertically. Values less than 2 are ignored (no spanning).
The index of the row
The index of the column
The rowspan value (number of rows the cell spans)
// Check if a cell spans multiple rows
const rowspan = bodyAreaModel.getRowspanAt(0, 0);
if (rowspan > 1) {
console.log(`This cell spans ${rowspan} rows`);
}
// Implementation example for a model with row spanning
getRowspanAt(rowIndex: number, columnIndex: number): number {
// Special case: first column spans 2 rows at the beginning
if (columnIndex === 0 && rowIndex % 2 === 0) return 2;
// No spanning for other cells
return 1;
}
Returns the value of the cell at the specified row and column indices. This is one of the most important methods in the area model, as it provides the actual data to be displayed in each cell.
The index of the row
The index of the column
The value at the specified cell
// Get the value of a cell
const value = bodyAreaModel.getValueAt(1, 2);
console.log(`Cell (1,2) contains: ${value}`);
// Implementation example for a 2D array model
getValueAt(rowIndex: number, columnIndex: number): any {
if (rowIndex < 0 || rowIndex >= this.data.length) return undefined;
const row = this.data[rowIndex];
if (columnIndex < 0 || columnIndex >= row.length) return undefined;
return row[columnIndex];
}
// Implementation example for an object array model
getValueAt(rowIndex: number, columnIndex: number): any {
const row = this.getRowByIndex(rowIndex);
if (!row) return undefined;
const property = this.columnDefs[columnIndex].property;
return row[property];
}
Returns the Y-coordinate (in pixels) of the top of the row at the specified index. This method is used for scrolling and positioning rows in the viewport.
The index of the row
The Y-coordinate of the top of the row, in pixels
// Get the Y-position of a row
const yPos = bodyAreaModel.getYPosByRowIndex(10);
console.log(`Row 10 starts at Y-position: ${yPos}px`);
// Implementation example with fixed row heights
getYPosByRowIndex(rowIndex: number): number {
return rowIndex * this.defaultRowHeight;
}
// Implementation example with variable row heights
getYPosByRowIndex(rowIndex: number): number {
// Use a pre-calculated array of Y-positions
return this.yPositions[rowIndex];
// Or calculate on-the-fly
// let yPos = 0;
// for (let i = 0; i < rowIndex; i++) {
// yPos += this.getRowHeight(i);
// }
// return yPos;
}
True if the row has children that are shown when it is expanded – with an active filter only children that match (or have a matching descendant) count. The arrow of a row without such children is hidden.
a tree row of this model
true if the row has displayed children
Initializes the area model. This method is called internally by the TableModel during initialization. It can be used to perform any necessary setup, such as calculating row positions.
// Implementation example
init(): void {
// Calculate y-positions for all rows
this.calculateYPositions();
// Initialize any other internal state
this.initialized = true;
}
Protected invalidateDrops derived values: cached aggregates of formulas and „Show values as“ (called by the table on filter,
sorting, editing, updateCells and api.repaint()).
Optional _change: DerivedValuesChangeIfthe changed rows (not used here)
1.1.95
True if a column of this model with this property is calculated (valueGetter or formula).
the property of the column
whether its values are computed
tableModel.getBodyModel().isCalculatedProperty?.("total"); // true
1.1.95
Determines whether the cell at the specified row and column indices is editable. If true, the user can edit the cell content.
The index of the row
The index of the column
True if the cell is editable, false otherwise
// Check if a cell is editable
const editable = bodyAreaModel.isEditable(1, 2);
if (editable) {
console.log('This cell can be edited by the user');
}
// Implementation example using column definitions
isEditable(rowIndex: number, columnIndex: number): boolean {
// Get editability from column definition
const columnDef = this.columnDefs[columnIndex];
return columnDef?.editable?.() ?? false;
}
// Implementation example with conditional editability
isEditable(rowIndex: number, columnIndex: number): boolean {
// Header cells are not editable
if (this.areaIdent === 'header') return false;
// First column is not editable (e.g., ID column)
if (columnIndex === 0) return false;
// Other cells in the body are editable
return this.areaIdent === 'body';
}
Determines whether this area supports filtering. If true, the area can be filtered using the externalFilterChanged method.
True if the area is filterable, false otherwise
// Check if an area is filterable
const filterable = bodyAreaModel.isFilterable();
if (filterable) {
console.log('This area supports filtering');
}
// Implementation example
isFilterable(): boolean {
// Only the body area is filterable
return this.areaIdent === 'body';
}
Determines whether the row at the specified index is checkable. If true, a checkbox will be rendered at the beginning of the row.
The index of the row
True if the row is checkable, false otherwise
// Check if a row is checkable
const checkable = bodyAreaModel.isRowCheckable(1);
if (checkable) {
console.log('This row can be checked by the user');
}
// Implementation example
isRowCheckable(rowIndex: number): boolean {
// All rows are checkable by default
return true;
// Or implement custom logic
// const row = this.getRowByIndex(rowIndex);
// return row && !row.locked; // Only unlocked rows are checkable
}
Returns the checked state of the row at the specified index.
The index of the row
The checked state of the row (true, false, or 'indeterminate'), or undefined if the row is not checkable
// Check if a row is checked
const checkedState = bodyAreaModel.isRowChecked(1);
if (checkedState === "full") {
console.log('This row is checked');
} else if (checkedState === "semi") {
console.log('This row is partially checked');
}
// Implementation example using a row selection model
isRowChecked(rowIndex: number): CheckedType | undefined {
if (!this.rowSelectionModel) return undefined;
const row = this.getRowByIndex(rowIndex);
return this.rowSelectionModel.isRowChecked(row);
}
Determines whether the cell at the specified row and column indices is selectable.
If true, the user can select the cell: the table draws the selection only on selectable body cells.
All built-in models and AreaModel return true (except the hidden and cover-grid models).
The index of the row
The index of the column
True if the cell is selectable, false otherwise
// Check if a cell is selectable
const selectable = bodyAreaModel.isSelectable(1, 2);
if (selectable) {
console.log('This cell can be selected by the user');
}
// Implementation example
isSelectable(rowIndex: number, columnIndex: number): boolean {
// All cells are selectable by default
return true;
// Or implement custom logic
// return this.areaIdent === 'body'; // Only body cells are selectable
}
Row drag: moves tree rows (with their children) in front of / behind the target row (siblings) or into it
("inside": last children, the target is expanded) – in place in rows and the children arrays;
parent and deep follow. See canMoveRows.
display indices of the dragged rows
the drop target (display index before the move)
true if moved
const treeModel = tableModel.getBodyModel() as AreaModelTree<OrderNode>;
treeModel.moveRows([3], { rowIndex: 0, position: "inside" });
tableApi.repaintHard(); // or simply tableApi.moveRows([3], { rowIndex: 0, position: "inside" })
1.1.95
Protected readRebuilds the displayed rows after the expanded state of rows has changed and applies the active filter
(see externalFilterChanged) again. The table calls it on every expand/collapse click. Call it
yourself after changing row.expanded from code, then repaint with tableApi.repaintHard()
(the row count changes).
Optional refilter: boolean = truerun the filter function again (needed after the rows changed). false after a
pure expand/collapse: whether a row matches does not depend on it (the table does this on every click –
before, the filter ran over all nodes for each click).
// expand all first-level rows from code
const treeModel = tableModel.getBodyModel() as AreaModelTree<OrderNode>;
for (const row of treeModel.rows) row.expanded = true;
treeModel.recalcVisibleTreeRows();
tableApi.repaintHard();
Protected setWrites an edited value of a calculated column through its valueSetter; without one: rejected.
Protected setSets the checked state of the row at the specified index.
The index of the row
The new checked state
// Check a row
bodyAreaModel.setRowChecked(1, true);
// Uncheck a row
bodyAreaModel.setRowChecked(2, false);
// Implementation example using a row selection model
setRowChecked(rowIndex: number, checked: boolean): void {
if (!this.rowSelectionModel) return;
const row = this.getRowByIndex(rowIndex);
if (row) {
this.rowSelectionModel.checkRow(row, checked);
}
}
Sets the value of a cell at the specified row and column indices. This method is called when a cell is edited by the user or programmatically.
The index of the row containing the cell
The index of the column containing the cell
The new value to set
// Set the value of a cell
areaModel.setValue(1, 2, "New Value");
// Implementation example for an object-based model
setValue(rowIndex: number, columnIndex: number, value: any): boolean {
const row = this.getRowByIndex(rowIndex);
if (!row) return false;
const property = this.columnDefs[columnIndex].property;
row[property] = value;
return true;
}
Sorts the rows of every level with your own function (children stay below their parent) and keeps the active
filter. Used by tableApi.sort(fn) – before, sorting a tree with a function did nothing.
compares two sibling rows – like the filter
function it gets the tree rows: your objects are a.data / b.data
tableApi.sort((a, b) => a.data.total - b.data.total); // sorts the siblings of every level by total
Represents a tree-based table model. Extends the AbstractAreaModel class.
The displayed rows always come from one pipeline: all tree rows (in their current, possibly sorted order) → rows whose parents are all expanded → active filter. Everything that changes one of these inputs (recalcVisibleTreeRows after an expand/collapse, externalFilterChanged, doSort, toggleExpandCollapseAll) runs the whole pipeline, so a filter survives expanding, collapsing and sorting.
Filter semantics: the filter function receives the tree row – your object is
row.data. It is called for every row, also for rows below collapsed parents. A row is shown if it or one of its descendants matches (row.keep) and all its parents are expanded. So a match below a collapsed node keeps that node visible (still collapsed); expanding it reveals the path to the match. The children of a matching row are not kept automatically.Example