Class AreaModelObjectArrayWithColumndefs<T>

Represents an area model defined by an object array with column definitions.

Description

The AreaModelObjectArrayWithColumndefs class extends AreaModelObjectArray to provide a specialized implementation where column definitions are a primary constructor parameter.

This class is particularly useful when working with table models where column definitions are essential for defining the structure of the table, especially in CRUD operations and other scenarios where column definitions need to be explicitly provided.

The main distinction from its parent class is the constructor parameter order, which prioritizes column definitions as a required parameter rather than an optional one.

Example

// Basic usage with an array of objects and explicit column definitions
const rows = [
{ id: 1, name: 'John', age: 30 },
{ id: 2, name: 'Jane', age: 25 },
{ id: 3, name: 'Bob', age: 40 }
];

const columnDefs: ColumnDefIf[] = [
new ColumnDef('id', 'ID', new Size(50, 'px')),
new ColumnDef('name', 'Name', new Size(150, 'px')),
new ColumnDef('age', 'Age', new Size(100, 'px'))
];

const bodyAreaModel = new AreaModelObjectArrayWithColumndefs<any>(
'body',
rows,
columnDefs,
30 // default row height
);

Example

// Using with CrudTableModelFactory
function createTableModel() {
const rows = fetchDataFromServer();
const columnDefs = [
new ColumnDef('id', 'ID', new Size(50, 'px')),
new ColumnDef('name', 'Name', new Size(150, 'px')),
new ColumnDef('age', 'Age', new Size(100, 'px'))
];

const tableModel = TableFactory.buildByTypedRowsParam({
rows,
columnDefs,
tableOptions: new TableOptions(),
fixedLeftColumnCount: 0,
fixedRightColumnCount: 1
});

// The body model is an instance of AreaModelObjectArrayWithColumndefs
const bodyModel = tableModel.getBodyModel() as AreaModelObjectArrayWithColumndefs<any>;

// Now you can work with the body model
return bodyModel;
}

Example

// Using custom row classes for selection and focus
const bodyAreaModel = new AreaModelObjectArrayWithColumndefs<any>(
'body',
rows,
columnDefs,
30, // default row height
'my-custom-selected-row', // custom selected row class
'my-custom-focused-row' // custom focused row class
);

See

Type Parameters

  • T

    The type of objects in the array. Each object represents a row in the table.

Hierarchy

Constructors

  • Creates an instance of AreaModelObjectArrayWithColumndefs.

    Type Parameters

    • T

    Parameters

    • areaIdent: AreaIdent

      Identifies which area of the table this model represents ('header', 'body', or 'footer')

    • rows: T[]

      The array of objects that represent the rows in this area

    • columnDefs: ColumnDefIf[]

      Definitions for the columns in this area (required parameter)

    • defaultRowHeight: number

      The default height for rows in this area (in pixels)

    • Optional selectedRowClass: string = 'ge-selected-row'

      CSS class to apply to selected rows

    • Optional focusedRowClass: string = 'ge-focused-row'

      CSS class to apply to the focused row

    Returns AreaModelObjectArrayWithColumndefs<T>

    Example

    const rows = [
    { id: 1, name: 'John', age: 30 },
    { id: 2, name: 'Jane', age: 25 }
    ];

    const columnDefs: ColumnDefIf[] = [
    new ColumnDef('id', 'ID', new Size(50, 'px')),
    new ColumnDef('name', 'Name', new Size(150, 'px')),
    new ColumnDef('age', 'Age', new Size(100, 'px'))
    ];

    const bodyAreaModel = new AreaModelObjectArrayWithColumndefs(
    'body',
    rows,
    columnDefs,
    30
    );

Properties

_focusedRowIndex: number = 0

The index of the currently focused row. This is used to apply the focused row styling.

Default

0
areaIdent: AreaIdent

Identifies which area of the table this model represents ('header', 'body', or 'footer')

cellRenderers: (undefined | CellRendererIf)[]
columnDefs: ColumnDefIf[]

Definitions for the columns in this area (required parameter)

defaultEditable: boolean = false

Columns without an own editable are editable (Excel-style editing, EditingOptionsIf.defaultEditable; set by the table). Row number, checkbox and group columns stay read only.

Since

1.1.99

defaultRowHeight: number

The default height for rows in this area (in pixels)

filteredRows: T[]

A copy of the rows array that can be filtered and sorted without affecting the original data. This array is used for rendering the table and is updated when filtering or sorting is applied.

focusedRowClass: string = 'ge-focused-row'

CSS class to apply to the focused row

properties: string[]

An array of property names extracted from the column definitions. These properties are used to access values from the row objects.

rowSelectionModel: undefined | CheckboxModelIf<any> = undefined

A model and controller for row checkbox selection. This property allows the area to support row selection via checkboxes.

Example

// 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);
rows: T[]

The array of objects that represent the rows in this area

selectedRowClass: string = 'ge-selected-row'

CSS class to apply to selected rows

yPositions: number[] = []

Methods

  • Changes the order of columns by moving a column from one position to another. This method updates both the properties array and calls the parent class implementation.

    Parameters

    • sourceColumnIndex: number

      The index of the column to move

    • targetColumnIndex: number

      The index where the column should be moved to

    Returns void

    Example

    // Move the second column (index 1) to the fourth position (index 3)
    bodyAreaModel.changeColumnOrder(1, 3);

    Example

    // Move the last column to the first position
    const lastIndex = tableModel.getColumnCount() - 1;
    bodyAreaModel.changeColumnOrder(lastIndex, 0);
  • The value of a row for a sort pass: a calculated column is computed once per row (memo for this pass, not 2·n·log n times); formula errors sort last (as undefined).

    Parameters

    • property: string

    Returns ((row) => unknown)

      • (row): unknown
      • The value of a row for a sort pass: a calculated column is computed once per row (memo for this pass, not 2·n·log n times); formula errors sort last (as undefined).

        Parameters

        • row: T

        Returns unknown

  • Sorts the filtered rows based on the provided sort items. This method supports sorting by multiple columns with different sort directions: the first item is the primary key, the following ones break ties.

    Parameters

    • sortItems: SortItem[]

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

    Returns boolean

    Always returns true to indicate sorting was performed

    Example

    // Sort by age in ascending order
    bodyAreaModel.doSort([{ columnIndex: 2, sortState: 'asc' }]);

    Example

    // Sort by name in descending order, then by age in ascending order
    bodyAreaModel.doSort([
    { columnIndex: 1, sortState: 'desc' },
    { columnIndex: 2, sortState: 'asc' }
    ]);

    Example

    // Clear sorting
    bodyAreaModel.doSort([new SortItem(0, '')]);
  • Applies an external filter function to the rows array. This method updates the filtered rows array without modifying the original rows array.

    Parameters

    • predictFn: FilterFunction<any>

      A function that returns true for rows to keep and false for rows to filter out

    Returns void

    Example

    // Filter rows where age is greater than 30
    bodyAreaModel.externalFilterChanged(row => row.age > 30);

    Example

    // Filter rows based on a search term
    const searchTerm = 'john';
    bodyAreaModel.externalFilterChanged(row =>
    row.name.toLowerCase().includes(searchTerm.toLowerCase())
    );

    Example

    // Clear all filters
    bodyAreaModel.externalFilterChanged(() => true);
  • Filters both the original rows and filtered rows arrays using the provided predicate function. Unlike externalFilterChanged, this method permanently modifies the original rows array.

    Parameters

    • predict: ((row) => boolean)

      A function that returns true for rows to keep and false for rows to filter out

        • (row): boolean
        • Parameters

          • row: T

          Returns boolean

    Returns void

    Example

    // Remove all rows where age is less than 30
    bodyAreaModel.filterRowsByPredict(row => row.age >= 30);
  • Searches through all rows to find a row that matches the given criteria based on the predicate function. This method searches within the original rows array, including rows that may have been filtered out.

    Parameters

    • criteria: Partial<T>

      A partial object containing the search criteria

    • predicate: ((criteria, row) => boolean)

      A function that takes the search criteria and a row, and returns true if the row matches the criteria

        • (criteria, row): boolean
        • Parameters

          • criteria: Partial<T>
          • row: T

          Returns boolean

    Returns undefined | T

    The first matching row from all rows, or undefined if no match is found

    Example

    // Find a user by ID in all rows
    const criteria = { id: 42 };
    const user = bodyAreaModel.findRowFromAllRowsByAllCriteria(
    criteria,
    (criteria, row) => row.id === criteria.id
    );

    Example

    // Find a user with a specific property value in all rows
    const criteria = { department: 'Engineering', role: 'Manager' };
    const user = bodyAreaModel.findRowFromAllRowsByAllCriteria(
    criteria,
    (criteria, row) => row.department === criteria.department && row.role === criteria.role
    );
  • Returns the first row from the filtered rows that matches the given criteria based on the provided predicate function. This method only searches within the filtered rows, not the original rows array.

    Parameters

    • criteria: Partial<T>

      A partial object containing the search criteria

    • predicate: ((criteria, row) => boolean)

      A function that takes the search criteria and a row, and returns true if the row matches the criteria

        • (criteria, row): boolean
        • Parameters

          • criteria: Partial<T>
          • row: T

          Returns boolean

    Returns undefined | T

    The first matching row, or undefined if no match is found

    Example

    // Find a user by name in the filtered rows
    const criteria = { name: 'John' };
    const user = bodyAreaModel.findRowFromFilteredRowsByAllCriteria(
    criteria,
    (criteria, row) => row.name === criteria.name
    );

    Example

    // Find a user by age range in the filtered rows
    const criteria = { minAge: 25, maxAge: 35 };
    const user = bodyAreaModel.findRowFromFilteredRowsByAllCriteria(
    criteria,
    (criteria, row) => row.age >= criteria.minAge && row.age <= criteria.maxAge
    );
  • Creates a comparator function for sorting rows based on a property and sort direction. This method supports custom sort comparators defined in column definitions.

    Parameters

    • property: string

      The property to sort by

    • f: number

      The sort direction factor: 1 for ascending, -1 for descending, 0 for no sorting

    Returns ((a, b) => number)

    A comparator function that compares two rows

      • (a, b): number
      • Creates a comparator function for sorting rows based on a property and sort direction. This method supports custom sort comparators defined in column definitions.

        Parameters

        • a: T
        • b: T

        Returns number

        A comparator function that compares two rows

        Example

        // inside a subclass: a comparator for sorting by name in ascending order
        const comparator = this.genericFlatTableSortComparator('name', 1);

        // Sort the rows using the comparator
        const sortedRows = [...this.getFilteredRows()].sort(comparator);

    Example

    // inside a subclass: a comparator for sorting by name in ascending order
    const comparator = this.genericFlatTableSortComparator('name', 1);

    // Sort the rows using the comparator
    const sortedRows = [...this.getFilteredRows()].sort(comparator);
  • Returns the original, unfiltered array of rows. This can be useful when you need to access all data regardless of any applied filters.

    Returns T[]

    The original array of row objects

    Example

    // Get all rows, including those filtered out
    const allRows = bodyAreaModel.getAllRows();

    // Calculate average age across all rows
    const totalAge = allRows.reduce((sum, row) => sum + row.age, 0);
    const averageAge = totalAge / allRows.length;
  • 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).

    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

    // Check if a cell spans multiple columns
    const colspan = headerAreaModel.getColspanAt(0, 0);
    if (colspan > 1) {
    console.log(`This header cell spans ${colspan} columns`);
    }

    Example

    // 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;
    }
  • Gets the custom CSS classes that should be applied to a cell. This method extends the parent class implementation to add selection and focus classes.

    Parameters

    • rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column (unused in this implementation)

    Returns string[]

    An array of CSS class names to apply to the cell

    Example

    // Get the CSS classes for a cell
    const classes = bodyAreaModel.getCustomClassesAt(1, 2);
    console.log('CSS classes:', classes);

    Example

    // Apply the classes to a cell element
    const cellElement = document.createElement('div');
    const classes = bodyAreaModel.getCustomClassesAt(rowIndex, columnIndex);
    cellElement.classList.add(...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.

    Parameters

    • _rowIndex: number

      The index of the row

    • _columnIndex: number

      The index of the column

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

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

    Example

    // Apply custom styles to cells
    const styles = bodyAreaModel.getCustomStyleAt(1, 2);
    console.log('Cell styles:', styles);

    Example

    // 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
    }
  • Retrieves the filtered and sorted rows from the dataset. These rows are used for rendering the table. Unlike getAllRows(), this method returns only the rows that match any applied filters.

    Returns T[]

    An array containing the filtered (and sorted) rows

    Example

    // Get all filtered rows
    const filteredRows = bodyAreaModel.getFilteredRows();

    // Count rows that match a certain condition
    const adultsCount = filteredRows.filter(row => row.age >= 18).length;
  • Returns the maximum colspan value that can occur in this area model. This value is used to optimize rendering performance.

    Returns number

    The maximum possible colspan value in this area

    Example

    // Get the maximum colspan for optimization
    const maxColspan = headerAreaModel.getMaxColspan();

    Example

    // 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.

    Returns number

    The maximum possible rowspan value in this area

    Example

    // Get the maximum rowspan for optimization
    const maxRowspan = bodyAreaModel.getMaxRowspan();

    Example

    // 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
    }
  • Returns the row object at the specified index from the filtered rows array. This method overrides the parent class implementation.

    Parameters

    • rowIndex: number

      The index of the row to retrieve

    Returns any

    The row object at the specified index, or undefined if the index is out of bounds

    Example

    // Get the first row object
    const row = bodyAreaModel.getRowByIndex(0);
    console.log('First row:', row);

    Example

    // Iterate through all rows
    for (let i = 0; i < bodyAreaModel.getRowCount(); i++) {
    const row = bodyAreaModel.getRowByIndex(i);
    console.log(`Row ${i}:`, row);
    }
  • Returns the height of the row at the specified index. This implementation always returns the default row height. Override this method in subclasses to support variable row heights.

    Parameters

    • _rowIndex: number

      The index of the row (unused in this implementation)

    Returns number

    The height of the row in pixels

    Example

    const rowHeight = bodyAreaModel.getRowHeight(0);
    console.log(`The first row has a height of ${rowHeight}px`);
  • 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.

    Parameters

    • row: any

      a row object (or TreeRow)

    • property: string

      the property of the column

    Returns unknown

    the value

    Example

    const body = tableModel.getBodyModel() as AreaModelObjectArray<Item>;
    body.getRowValue({ price: 25, quantity: 10 }, "total"); // 250

    Since

    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).

    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

    // Check if a cell spans multiple rows
    const rowspan = bodyAreaModel.getRowspanAt(0, 0);
    if (rowspan > 1) {
    console.log(`This cell spans ${rowspan} rows`);
    }

    Example

    // 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;
    }
  • Gets the value at the specified row and column indices. This method handles tree rows and nested properties.

    Parameters

    • rowIndex: number

      The index of the row

    • columnIndex: number

      The index of the column

    Returns any

    The value at the specified cell, or an empty string if not found

    Example

    // Get the value in the first row, second column
    const value = bodyAreaModel.getValueAt(0, 1);
    console.log(`The value is: ${value}`);

    Example

    // Iterate through all cells in a row
    const rowIndex = 0;
    for (let colIndex = 0; colIndex < columnDefs.length; colIndex++) {
    const value = bodyAreaModel.getValueAt(rowIndex, colIndex);
    console.log(`Cell (${rowIndex}, ${colIndex}): ${value}`);
    }
  • Gets a value from an object using a property path. This method supports accessing nested properties using dot notation (e.g., 'person.name').

    Parameters

    • t: T

      The object to get the value from

    • property: string

      The property path to access (e.g., 'name' or 'person.contact.email')

    Returns any

    The value at the specified property path, or undefined if not found

    Example

    const user = { id: 1, name: 'John', contact: { email: 'john@example.com' } };

    // Access simple property
    const name = bodyAreaModel.getValueByT(user, 'name');
    console.log(name); // 'John'

    // Access nested property
    const email = bodyAreaModel.getValueByT(user, 'contact.email');
    console.log(email); // 'john@example.com'
  • 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.

    Parameters

    • rowIndex: number

      The index of the row

    Returns number

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

    Example

    // Get the Y-position of a row
    const yPos = bodyAreaModel.getYPosByRowIndex(10);
    console.log(`Row 10 starts at Y-position: ${yPos}px`);

    Example

    // Implementation example with fixed row heights
    getYPosByRowIndex(rowIndex: number): number {
    return rowIndex * this.defaultRowHeight;
    }

    Example

    // 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;
    }
  • 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.

    Returns void

    Example

    // Implementation example
    init(): void {
    // Calculate y-positions for all rows
    this.calculateYPositions();

    // Initialize any other internal state
    this.initialized = true;
    }
  • Determines whether the cell at the specified row and column indices is editable. If true, the user can edit the cell content.

    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

    // Check if a cell is editable
    const editable = bodyAreaModel.isEditable(1, 2);
    if (editable) {
    console.log('This cell can be edited by the user');
    }

    Example

    // 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;
    }

    Example

    // 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.

    Returns boolean

    True if the area is filterable, false otherwise

    Example

    // Check if an area is filterable
    const filterable = bodyAreaModel.isFilterable();
    if (filterable) {
    console.log('This area supports filtering');
    }

    Example

    // 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.

    Parameters

    • _rowIndex: number

      The index of the row

    Returns boolean

    True if the row is checkable, false otherwise

    Example

    // Check if a row is checkable
    const checkable = bodyAreaModel.isRowCheckable(1);
    if (checkable) {
    console.log('This row can be checked by the user');
    }

    Example

    // 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.

    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

    // 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');
    }

    Example

    // 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).

    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

    // Check if a cell is selectable
    const selectable = bodyAreaModel.isSelectable(1, 2);
    if (selectable) {
    console.log('This cell can be selected by the user');
    }

    Example

    // 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 the rows in the display order and writes that order back to getAllRows – in place (like Array.prototype.sort: with TableFactory.createTableModel({ rows }) your array has the new order). Works only without a hiding filter (canMoveRows). The table repaints after a drop; from code use tableApi.moveRows().

    Parameters

    • rowIndices: number[]

      display indices of the dragged rows

    • target: RowDropTargetIf

      the drop target (display index before the move)

    Returns boolean

    true if moved

    Example

    bodyAreaModel.moveRows([2], { rowIndex: 6, position: "after" });   // row 3 becomes row 7
    

    Since

    1.1.95

  • Sets the checked state of the row at the specified index.

    Parameters

    • rowIndex: number

      The index of the row

    • checked: boolean

      The new checked state

    Returns void

    Example

    // Check a row
    bodyAreaModel.setRowChecked(1, true);

    // Uncheck a row
    bodyAreaModel.setRowChecked(2, false);

    Example

    // 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);
    }
    }
  • Replaces the current rows array with a new one. This also resets the filtered rows to match the new rows array.

    Parameters

    • rows: T[]

      The new array of row objects

    Returns void

    Example

    // Replace the current rows with new data
    const newRows = [
    { id: 4, name: 'Alice', age: 35 },
    { id: 5, name: 'Charlie', age: 45 }
    ];
    bodyAreaModel.setRows(newRows);
  • 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.

    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

    // Set the value of a cell
    areaModel.setValue(1, 2, "New Value");

    Example

    // 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 filtered rows using a custom comparator function. This method provides more flexibility than doSort() for complex sorting logic.

    Parameters

    • 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: T
          • b: T

          Returns number

    Returns void

    Example

    // Sort by name length
    bodyAreaModel.sort((a, b) => a.name.length - b.name.length);

    Example

    // Sort by a computed value
    bodyAreaModel.sort((a, b) => {
    const scoreA = a.wins * 3 + a.draws;
    const scoreB = b.wins * 3 + b.draws;
    return scoreB - scoreA; // Descending order
    });