@progress/kendo-angular-grid
Version:
Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.
161 lines (160 loc) • 5.33 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 { Injectable, EventEmitter } from '@angular/core';
import { zip } from 'rxjs';
import { leafColumns } from '../columns/column-common';
import { take } from 'rxjs/operators';
import * as i0 from "@angular/core";
/**
* @hidden
*/
const isLocked = column => column.parent ? isLocked(column.parent) : !!column.locked;
/**
* @hidden
*/
const resizeArgs = (column, extra) => Object.assign({
columns: leafColumns([column]),
locked: isLocked(column)
}, extra);
/**
* @hidden
*/
export class ColumnResizingService {
changes = new EventEmitter();
adjacentColumn;
areColumnsReordered = false;
isShiftPressed = false;
originalWidth;
draggedGroupColumn;
resizedColumns;
autoFitResize = false;
column;
tables = [];
batch = null;
start(column) {
this.trackColumns(column);
const columns = (this.column.isColumnGroup ? [column] : [])
.concat(leafColumns([column]));
this.changes.emit({
columns: columns,
locked: isLocked(this.column),
type: 'start'
});
}
resizeColumns(deltaPercent) {
const action = resizeArgs(this.column, {
deltaPercent,
type: 'resizeColumn'
});
this.changes.emit(action);
}
resizeTable(column, delta) {
const action = resizeArgs(column, {
delta,
type: 'resizeTable'
});
this.changes.emit(action);
}
resizedColumn(state) {
this.resizedColumns.push(state);
}
end() {
this.changes.emit({
columns: [],
resizedColumns: this.resizedColumns,
type: 'end'
});
this.restoreInitialMaxMinWidths();
this.adjacentColumn = null;
this.draggedGroupColumn = null;
this.autoFitResize = false;
}
registerTable(tableMetadata) {
this.tables.push(tableMetadata);
const unregisterTable = () => {
this.tables.splice(this.tables.indexOf(tableMetadata), 1);
};
return unregisterTable;
}
measureColumns(info) {
if (this.batch !== null) {
this.batch.push(...info);
}
else {
this.autoFitBatch(info, () => this.end());
}
}
autoFit(...columns) {
const nonLockedColumns = columns.filter(column => !column.isLocked);
this.autoFitStart(nonLockedColumns);
this.autoFitBatch(this.batch, () => {
if (nonLockedColumns.length < columns.length) {
const lockedColumns = columns.filter(column => column.isLocked);
this.autoFitStart(lockedColumns);
this.autoFitBatch(this.batch, () => this.end());
}
else {
this.end();
}
});
}
trackColumns(column) {
this.resizedColumns = [];
this.column = column;
}
autoFitStart(columns) {
this.batch = [];
this.resizedColumns = [];
if (columns.length === 0) {
return;
}
const locked = columns[0].isLocked;
this.changes.emit({
type: 'start',
columns,
locked
});
this.changes.emit({
type: 'triggerAutoFit',
columns,
locked
});
}
autoFitBatch(info, onComplete) {
const locked = info.length > 0 ? info[0].column.isLocked : false;
const observables = this.tables
.filter(table => table.locked === locked)
.map(table => table.autoFit(info));
zip(...observables)
.pipe(take(1))
.subscribe(widths => {
this.changes.emit({
columns: info.map(i => i.column),
type: 'autoFitComplete',
widths,
locked
});
if (onComplete) {
onComplete();
}
});
this.batch = null;
}
restoreInitialMaxMinWidths() {
if (this.adjacentColumn) {
this.adjacentColumn.maxResizableWidth = this.adjacentColumn.initialMaxResizableWidth;
this.adjacentColumn.minResizableWidth = this.adjacentColumn.initialMinResizableWidth;
}
if (this.column) {
this.column.maxResizableWidth = this.column.initialMaxResizableWidth;
this.column.minResizableWidth = this.column.initialMinResizableWidth;
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ColumnResizingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ColumnResizingService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ColumnResizingService, decorators: [{
type: Injectable
}] });