Class AreaModelPivotFooter<T>

The total row of a pivot table: the label "Total" in the group column and the column totals (cells, subtotals, grand total) of the AreaModelPivot. The totals come from the source rows (merged states), never from the displayed rows – an average stays the average of all rows. Created by PivotFactory.createTableModel (totalRow: false → no row).

Example

const footer = tableModel.getAreaModel("footer") as AreaModelPivotFooter;
footer.getValueAt(0, pivotModel.getPivotBody().getColumnIndex([])); // 450 – the grand total

Since

1.1.94

Type Parameters

  • T = any

Hierarchy

Implements

Constructors

Properties

areaIdent: AreaIdent = "body"

The identifier for one of the areas: header, body, footer. This property determines which area of the table this model represents. Default value is "body".

Example

// Creating an area model for the header
const headerModel = new AreaModel();
headerModel.areaIdent = "header";
defaultRowHeight: number = 34

row height in px

rowSelectionModel: undefined | CheckboxModelIf<any> = undefined

A model and controller for row checkbox selection. This property allows the area to support row selection via checkboxes. Default value is undefined (no row selection).

Example

// Creating a checkbox model for row selection
import { CheckboxModel } from "@guiexpert/table";

const bodyModel = new AreaModel();
bodyModel.rowSelectionModel = new CheckboxModel();
type: "AreaModelPivotFooter" = "AreaModelPivotFooter"

Marker (works across copies of the core).

Methods

  • 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 base implementation does nothing and should be overridden by subclasses that support column reordering.

    Parameters

    • _sourceColumnIndex: number

      The index of the column to move

    • _targetColumnIndex: number

      The index where the column should be moved to

    Returns void

    Example

    // Override in a subclass to implement column reordering
    changeColumnOrder(sourceColumnIndex: number, targetColumnIndex: number): void {
    // Move the column in the internal data structure
    this.arrayMove(this.columns, sourceColumnIndex, targetColumnIndex);
    }
  • Sorts the rows in this area based on the provided sort items. Called when the user double-clicks a sortable column header (and by TableApi.sortByColumn). The base implementation returns false (no sorting performed) and should be overridden by subclasses that hold their rows themselves.

    Parameters

    • _sortItems: SortItem[]

      An array of sort items, each containing a column index and sort direction

    Returns boolean

    True if sorting was performed, false otherwise

    Example

    class SortableRows extends AreaModel {
    constructor(private readonly rows: any[][]) {
    super();
    this.areaIdent = "body";
    }
    override getRowCount(): number { return this.rows.length; }
    override getValueAt(row: number, col: number): any { return this.rows[row][col]; }

    override doSort(sortItems: SortItem[]): boolean {
    if (!sortItems.length) return false;
    const { columnIndex, sortState } = sortItems[0];
    const direction = sortState === "asc" ? 1 : -1;
    this.rows.sort((a, b) => (a[columnIndex] < b[columnIndex] ? -1 : a[columnIndex] > b[columnIndex] ? 1 : 0) * direction);
    return true;
    }
    }
  • Applies a filter function to the rows in this area. This method is called when a filter is applied to the table. The base implementation does nothing and should be overridden by subclasses that support filtering.

    Type Parameters

    • T

    Parameters

    • _predictFn: FilterFunction<T>

      A function that takes a row and returns true if the row should be visible

    Returns void

    Example

    // Override in a subclass to implement filtering
    externalFilterChanged<T>(predictFn: FilterFunction<T>): void {
    // Apply the filter to the rows
    this.filteredRows = this.rows.filter(predictFn);
    }
  • Returns a cell renderer for the cell at the specified row and column indices. A cell renderer is responsible for rendering the cell content in a custom way. The base implementation returns undefined (default rendering) and should be overridden by subclasses that support custom cell rendering.

    Parameters

    • _rowIndex: number

      The index of the row

    • columnIndex: number

      The index of the column

    Returns undefined | CellRendererIf

    A cell renderer instance, or undefined for default rendering

    Example

    // Override in a subclass to provide custom cell renderers
    getCellRenderer(rowIndex: number, columnIndex: number): CellRendererIf | undefined {
    // Get renderer from column definition
    const columnDef = this.columnDefs[columnIndex];
    return columnDef?.rendererMap?.[this.areaIdent];
    }
  • 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. The base implementation returns 0 (no spanning) and should be overridden by subclasses that support column spanning.

    Parameters

    • _rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column

    Returns number

    The colspan value (number of columns the cell spans)

    Example

    // Override in a subclass to implement 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 base implementation returns an empty array (no custom classes) and should be overridden by subclasses that support custom cell styling.

    Parameters

    • rowIndex: number

      The index of the row

    • columnIndex: number

      The index of the column

    Returns string[]

    An array of CSS class names

    Example

    // Override in a subclass to implement custom cell classes
    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');
    }

    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 base implementation returns undefined (no custom styles) and should be overridden by subclasses that support custom cell styling.

    Parameters

    • _rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column

    Returns undefined | {
        [p: string]: string;
    }

    An object with CSS style properties, or undefined if no custom styles

    Example

    // Override in a subclass to implement custom cell styles
    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
    }
  • Returns the maximum colspan value that can occur in this area model. This value is used to optimize rendering performance. The base implementation returns 0 (no colspans) and should be overridden by subclasses that support column spanning.

    Returns number

    The maximum possible colspan value in this area

    Example

    // Override in a subclass to specify maximum colspan
    getMaxColspan(): number {
    // 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 base implementation returns 0 (no rowspans) and should be overridden by subclasses that support row spanning.

    Returns number

    The maximum possible rowspan value in this area

    Example

    // Override in a subclass to specify maximum rowspan
    getMaxRowspan(): number {
    // If the model has rowspans, return the maximum possible value
    return 2; // If some cells span up to 2 rows
    }
  • Returns the row object at the specified index. This method provides access to the underlying data structure. The base implementation returns undefined and should be overridden by subclasses that have a row-based data structure.

    Parameters

    • _rowIndex: number

      The index of the row

    Returns any

    The row object, or undefined if the row doesn't exist

    Example

    // Override in a subclass to provide access to row data
    getRowByIndex(rowIndex: number): any {
    if (rowIndex < 0 || rowIndex >= this.data.length) return undefined;
    return this.data[rowIndex];
    }
  • Returns the height of the row at the specified index, in pixels. This method allows for variable row heights in the table. The base implementation returns 0 and should be overridden by all subclasses.

    Parameters

    • _rowIndex: number

      The index of the row

    Returns number

    The height of the row in pixels

    Example

    // Override in a subclass to provide fixed row heights
    getRowHeight(rowIndex: number): number {
    return 30; // 30px for all rows
    }

    Example

    // Override in a subclass to provide variable row heights
    getRowHeight(rowIndex: number): number {
    // First row is taller
    if (rowIndex === 0) return 50;

    // Default height for other rows
    return 30;
    }
  • 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. The base implementation returns 0 (no spanning) and should be overridden by subclasses that support row spanning.

    Parameters

    • _rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column

    Returns number

    The rowspan value (number of rows the cell spans)

    Example

    // Override in a subclass to implement 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 a string representation of the cell value at the specified row and column indices. This method is used when exporting the table data or copying to clipboard. The base implementation returns an empty string and should be overridden by subclasses that need custom text conversion.

    Parameters

    • rowIndex: number

      The index of the row

    • columnIndex: number

      The index of the column

    Returns string

    The text value of the specified cell

    Example

    // Override in a subclass to provide text representation
    getTextValueAt(rowIndex: number, columnIndex: number): string {
    const value = this.getValueAt(rowIndex, columnIndex);

    // Handle different data types appropriately
    if (value === null || value === undefined) return '';
    if (value instanceof Date) return value.toISOString();
    return String(value);
    }
  • Returns the tooltip text for the cell at the specified row and column indices. This tooltip will be displayed when the user hovers over the cell. The base implementation returns undefined (no tooltip) and should be overridden by subclasses that support tooltips.

    Parameters

    • _rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column

    Returns any

    The tooltip content (usually a string)

    Example

    // Override in a subclass to provide tooltips
    getTooltipAt(rowIndex: number, columnIndex: number): any {
    // Use the cell value as the tooltip
    return this.getValueAt(rowIndex, columnIndex);

    // Or provide a more detailed tooltip
    // const value = this.getValueAt(rowIndex, columnIndex);
    // return `Value: ${value}\nRow: ${rowIndex}\nColumn: ${columnIndex}`;
    }
  • 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 base implementation returns undefined and should be overridden by all subclasses.

    Parameters

    • rowIndex: number

      The index of the row

    • columnIndex: number

      The index of the column

    Returns any

    The value at the specified cell

    Example

    // Override in a subclass 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];
    }

    Example

    // Override in a subclass 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 base implementation computes it from getConstantRowHeight() (O(1)) or by summing up getRowHeight() of all rows above (O(n)) – override it for large models with variable row heights. (Before 1.1.85 the base implementation returned 0.)

    Parameters

    • rowIndex: number

      The index of the row

    Returns number

    The Y-coordinate of the top of the row, in pixels

    Example

    // Override in a subclass with fixed row heights
    getYPosByRowIndex(rowIndex: number): number {
    return rowIndex * this.defaultRowHeight;
    }

    Example

    // Override in a subclass 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;
    }
  • 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. The base implementation does nothing and can be overridden by subclasses that need initialization.

    Returns void

    Example

    // Override in a subclass to perform initialization
    init(): void {
    // Calculate y-positions for all rows
    this.yPositions = [];
    let currentY = 0;

    for (let i = 0; i < this.getRowCount(); i++) {
    this.yPositions[i] = currentY;
    currentY += this.getRowHeight(i);
    }
    }
  • Determines whether the cell at the specified row and column indices is editable. If true, the user can edit the cell content. The base implementation returns false (not editable) and should be overridden by subclasses that support cell editing.

    Parameters

    • _rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column

    Returns boolean

    True if the cell is editable, false otherwise

    Example

    // Override in a subclass to implement cell 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. The base implementation returns false (not filterable) and should be overridden by subclasses that support filtering.

    Returns boolean

    True if the area is filterable, false otherwise

    Example

    // Override in a subclass to enable filtering
    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 base implementation returns false (not checkable) and should be overridden by subclasses that support row selection.

    Parameters

    • _rowIndex: number

      The index of the row

    Returns boolean

    True if the row is checkable, false otherwise

    Example

    // Override in a subclass to implement row checkability
    isRowCheckable(rowIndex: number): boolean {
    // All rows in the body are checkable
    if (this.areaIdent !== 'body') return false;

    // Except for special rows
    const row = this.getRowByIndex(rowIndex);
    return row && !row.locked;
    }
  • Returns the checked state of the row at the specified index. The base implementation returns undefined (not checked) and should be overridden by subclasses that support row selection.

    Parameters

    • _rowIndex: number

      The index of the row

    Returns undefined | CheckedType

    The checked state of the row (true, false, or 'indeterminate'), or undefined if the row is not checkable

    Example

    // Override in a subclass to implement row checked state
    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. The table draws the selection (of the SelectionModel) only on selectable body cells.

    Default: true – all cells are selectable, like in all built-in area models (up to 1.1.90 the default of AreaModel was false: a selection on an own model was not drawn). Override it to exclude cells, e.g. a column of row numbers.

    Parameters

    • _rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column

    Returns boolean

    True if the cell is selectable, false otherwise

    Example

    // Override in a subclass: the first column (row numbers) never shows a selection
    override isSelectable(_rowIndex: number, columnIndex: number): boolean {
    return columnIndex > 0;
    }
  • Sets the checked state of the row at the specified index. The base implementation does nothing and should be overridden by subclasses that support row selection.

    Parameters

    • _rowIndex: number

      The index of the row

    • _checked: boolean

      The new checked state

    Returns void

    Example

    // Override in a subclass to implement row checking
    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 base implementation returns false (value not set) and should be overridden by subclasses that support cell editing.

    Parameters

    • _rowIndex: number

      The index of the row containing the cell

    • _columnIndex: number

      The index of the column containing the cell

    • _value: any

      The new value to set

    Returns boolean

    • True if the value was successfully set, false otherwise

    Example

    // Override in a subclass to implement cell value setting
    setValue(rowIndex: number, columnIndex: number, value: any): boolean {
    // Check if the cell is editable
    if (!this.isEditable(rowIndex, columnIndex)) return false;

    // For a 2D array model
    if (rowIndex >= 0 && rowIndex < this.data.length) {
    const row = this.data[rowIndex];
    if (columnIndex >= 0 && columnIndex < row.length) {
    row[columnIndex] = value;
    return true;
    }
    }

    return false;
    }
  • Sorts the rows in this area using a custom comparator function. This method provides more flexibility than doSort for complex sorting logic. The base implementation does nothing and should be overridden by subclasses that support custom sorting.

    Parameters

    • Optional _compareFn: ((a, b) => number)

      A function that compares two rows and returns a number:

      • Negative if a should come before b
      • Positive if a should come after b
      • Zero if they are equivalent for sorting purposes
        • (a, b): number
        • Parameters

          • a: any
          • b: any

          Returns number

    Returns void

    Example

    // Override in a subclass to implement custom sorting
    sort(compareFn?: (a: any, b: any) => number): void {
    if (!compareFn) return;

    // Apply the custom sort function
    this.rows.sort(compareFn);
    }