UNPKG

@progress/kendo-angular-treelist

Version:

Kendo UI TreeList for Angular - Display hierarchical data in an Angular tree grid view that supports sorting, filtering, paging, and much more.

127 lines (126 loc) 3.79 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { ItemMap } from './item-map'; import { ModelCell } from './model-cell'; /** * @hidden * * Contains information for the currently rendered rows and cells. */ export class NavigationModel { rows = new ItemMap(); get firstRow() { return this.rows.first; } get lastRow() { return this.rows.last; } registerCell(cell) { const row = this.rows.getItem(cell.logicalRowIndex); if (!row) { return; } const modelCell = new ModelCell(row, cell); row.cells.setItem(cell.logicalColIndex, modelCell); return modelCell; } unregisterCell(index, rowIndex, cell) { const row = this.rows.getItem(rowIndex); if (row) { const match = row.cells.getItem(index); if (match && match.uid === cell.uid) { row.cells.removeItem(index); } } } registerRow(row) { const modelRow = { uid: row.uid, index: row.logicalRowIndex, dataItem: row.dataItem, dataRowIndex: row.dataRowIndex, cells: new ItemMap(), isNew: row.isNew }; this.rows.setItem(row.logicalRowIndex, modelRow); } updateRow(row) { const current = this.rows.getItem(row.logicalRowIndex); if (current) { Object.assign(current, { dataItem: row.dataItem, dataRowIndex: row.dataRowIndex }); } } unregisterRow(index, row) { const match = this.rows.getItem(index); if (match && match.uid === row.uid) { this.rows.removeItem(index); } } cellRange(cell) { if (cell) { const start = cell.colIndex; const end = cell.colIndex + (cell.colSpan || 1) - 1; return { start, end }; } return {}; } rowRange(cell) { if (cell) { const start = cell.rowIndex; const end = cell.rowIndex + (cell.rowSpan || 1) - 1; return { start, end }; } return {}; } nextRow(rowIndex, offset) { const rows = this.rows.toArray(); const row = this.rows.getItem(rowIndex); const position = rows.indexOf(row); const next = rows[position + offset]; return next; } findRow(index) { return this.rows.getItem(index); } findCell(index, row) { if (!row) { return; } const rowIndex = row.index; let cell = row.cells.getItem(index); let currentIndex = rowIndex; while (!cell && row) { row = this.rows.getItem(currentIndex); cell = this.rowCell(index, row); currentIndex--; } if (cell && rowIndex <= row.index + (cell.rowSpan || 1) - 1) { return cell; } } rowCell(index, row) { if (!row || !row.cells.count) { return; } const firstCell = row.cells.first; let cell, currentIndex = index; while (!cell && currentIndex >= firstCell.colIndex) { cell = row.cells.getItem(currentIndex); currentIndex--; } if (cell && index <= cell.colIndex + (cell.colSpan || 1) - 1) { return cell; } } }