@progress/kendo-angular-grid
Version:
Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.
70 lines (69 loc) • 2.86 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 } from '@angular/core';
import { Subject } from 'rxjs';
import { getGroupRowArgs } from './utils';
import * as i0 from "@angular/core";
const isChildIndex = (targetIndex, parentIndex) => {
const sameIndex = parentIndex === targetIndex;
const lastSeparatorIndex = targetIndex.lastIndexOf('_');
const sameSubGroupIndex = targetIndex.substring(0, lastSeparatorIndex) === parentIndex;
return !sameIndex && sameSubGroupIndex;
};
/**
* @hidden
*/
export class GroupsService {
changes = new Subject();
userCallback;
rowState = new Set();
reset() {
this.rowState.clear();
}
ngOnDestroy() {
this.reset();
}
isExpanded(groupArgs) {
if (this.userCallback) {
return this.userCallback(groupArgs);
}
return !this.rowState.has(groupArgs.groupIndex);
}
isInExpandedGroup(groupItem) {
let expanded = true;
while (groupItem && expanded) {
expanded = this.isExpanded({
group: groupItem.data,
groupIndex: groupItem.index,
parentGroup: getGroupRowArgs(groupItem.parentGroup)
});
groupItem = groupItem.parentGroup;
}
return expanded;
}
toggleRow(groupItem, emit = true) {
const parentGroup = getGroupRowArgs(groupItem.parentGroup);
const expand = !this.isExpanded({ group: groupItem.data, groupIndex: groupItem.index, parentGroup });
this.changes.next({ group: groupItem.data, expand, groupIndex: groupItem.index, parentGroup, emit });
// if usercallback is given, the rowState should be ignored
if (this.userCallback) {
return;
}
if (expand) {
this.rowState.delete(groupItem.index);
}
else {
this.rowState.add(groupItem.index);
}
}
expandChildren(parentIndex) {
this.rowState.forEach(index => isChildIndex(index, parentIndex) && this.rowState.delete(index));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: GroupsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: GroupsService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: GroupsService, decorators: [{
type: Injectable
}] });