@progress/kendo-angular-grid
Version:
Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.
139 lines (138 loc) • 4.15 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* 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';
/**
* @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 colIndex = cell.logicalColIndex;
const modelCell = {
uid: cell.uid,
colIndex,
rowIndex: row.index,
colSpan: cell.colSpan,
rowSpan: cell.rowSpan,
detailExpandCell: cell.detailExpandCell,
dataItem: row.dataItem,
dataRowIndex: row.dataRowIndex,
focusGroup: cell.focusGroup
};
row.cells.setItem(colIndex, modelCell);
if (cell.groupItem) {
row.groupItem = cell.groupItem;
}
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()
};
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;
}
}
}