Skip to content

Commit dbf6c29

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Define indicidual containers for each row dimension with its own virtualization synched to the same external scrollbar.
1 parent cd35075 commit dbf6c29

File tree

7 files changed

+94
-128
lines changed

7 files changed

+94
-128
lines changed

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
414414

415415
if (this.igxForScrollOrientation === 'vertical') {
416416
this.dc.instance._viewContainer.element.nativeElement.style.top = '0px';
417-
this.scrollComponent = vc.createComponent(VirtualHelperComponent).instance;
417+
this.scrollComponent = this.syncScrollService.getScrollMaster(this.igxForScrollOrientation) || vc.createComponent(VirtualHelperComponent).instance;
418418
this._maxHeight = this._calcMaxBrowserHeight();
419419
this.scrollComponent.size = this.igxForOf ? this._calcHeight() : 0;
420420
this.syncScrollService.setScrollMaster(this.igxForScrollOrientation, this.scrollComponent);
@@ -1115,20 +1115,16 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
11151115
protected initSizesCache(items: any[]): number {
11161116
let totalSize = 0;
11171117
let size = 0;
1118-
const dimension = this.igxForScrollOrientation === 'horizontal' ?
1119-
this.igxForSizePropName : 'height';
1118+
const dimension = this.igxForSizePropName || 'height';
11201119
let i = 0;
11211120
this.sizesCache = [];
11221121
this.heightCache = [];
11231122
this.sizesCache.push(0);
11241123
const count = this.isRemote ? this.totalItemCount : items.length;
11251124
for (i; i < count; i++) {
1125+
size = this._getItemSize(items[i], dimension);
11261126
if (dimension === 'height') {
1127-
// cols[i][dimension] = parseInt(this.igxForItemSize, 10) || 0;
1128-
size = parseInt(this.igxForItemSize, 10) || 0;
11291127
this.heightCache.push(size);
1130-
} else {
1131-
size = this._getItemSize(items[i], dimension);
11321128
}
11331129
totalSize += size;
11341130
this.sizesCache.push(totalSize);

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
</igx-pivot-header-row>
2020

2121
<div igxGridBody (keydown.control.c)="copyHandler($event)" (copy)="copyHandler($event)" class="igx-grid__tbody" role="rowgroup">
22-
<div #rowDimensionContainer role="rowgroup" class='igx-grid__tbody-pivot-dimension'>
22+
<div *ngFor='let dim of rowDimensions' #rowDimensionContainer role="rowgroup" class='igx-grid__tbody-pivot-dimension'>
2323
<ng-template igxGridFor let-rowData [igxGridForOf]="dataView
24-
| pivotGridMRL:pivotConfiguration:pivotKeys:pipeTrigger"
24+
| pivotGridCellMerging:pivotConfiguration:pivotKeys:pipeTrigger"
2525
let-rowIndex="index" [igxForScrollOrientation]="'vertical'" [igxForScrollContainer]='verticalScroll'
2626
[igxForContainerSize]='calcHeight'
27-
[igxForItemSize]="hasColumnLayouts ? rowHeight * multiRowLayoutRowSize + 1 : renderedRowHeight"
27+
[igxForItemSize]="renderedRowHeight"
2828
#verticalRowDimScrollContainer>
2929
<igx-pivot-row-dimension-content role='row' class="igx-grid-thead" [grid]="this"
30+
[dimension]='dim'
3031
[rowIndex]='rowIndex' [rowData]='rowData'
31-
[density]="displayDensity" [width]="pivotRowWidths">
32+
[density]="displayDensity" [width]="resolveRowDimensionWidth(dim)">
3233
</igx-pivot-row-dimension-content>
3334
</ng-template>
3435
</div>

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,12 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10341034
/**
10351035
* @hidden @internal
10361036
*/
1037-
@ViewChild('verticalRowDimScrollContainer', { read: IgxGridForOfDirective, static: true })
1038-
public verticalRowDimScrollContainer: IgxGridForOfDirective<any>;
1037+
@ViewChildren('verticalRowDimScrollContainer', { read: IgxGridForOfDirective})
1038+
public verticalRowDimScrollContainers: QueryList<IgxGridForOfDirective<any>>;
10391039

10401040
protected verticalScrollHandler(event) {
1041-
this.verticalRowDimScrollContainer.onScroll(event);
10421041
super.verticalScrollHandler(event);
1043-
1042+
this.verticalRowDimScrollContainers.forEach(x => x.onScroll(event));
10441043
}
10451044

10461045
/**

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IgxGridModule } from '../grid/grid.module';
33
import { IgxPivotGridComponent } from './pivot-grid.component';
44
import { IgxPivotRowComponent } from './pivot-row.component';
55
import { IgxPivotRowPipe, IgxPivotColumnPipe, IgxPivotGridFilterPipe,
6-
IgxPivotRowExpansionPipe, IgxPivotGridSortingPipe, IgxPivotGridColumnSortingPipe, IgxPivotRowMRLPipe } from './pivot-grid.pipes';
6+
IgxPivotRowExpansionPipe, IgxPivotGridSortingPipe, IgxPivotGridColumnSortingPipe, IgxPivotCellMergingPipe } from './pivot-grid.pipes';
77
import { IgxGridComponent } from '../grid/grid.component';
88
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
99
import { IgxPivotRowDimensionContentComponent } from './pivot-row-dimension-content.component';
@@ -25,7 +25,7 @@ import { IgxPivotRowDimensionHeaderGroupComponent } from './pivot-row-dimension-
2525
IgxPivotGridFilterPipe,
2626
IgxPivotGridSortingPipe,
2727
IgxPivotGridColumnSortingPipe,
28-
IgxPivotRowMRLPipe
28+
IgxPivotCellMergingPipe
2929
],
3030
exports: [
3131
IgxGridModule,
@@ -40,7 +40,7 @@ import { IgxPivotRowDimensionHeaderGroupComponent } from './pivot-row-dimension-
4040
IgxPivotGridFilterPipe,
4141
IgxPivotGridSortingPipe,
4242
IgxPivotGridColumnSortingPipe,
43-
IgxPivotRowMRLPipe
43+
IgxPivotCellMergingPipe
4444
],
4545
imports: [
4646
IgxGridModule,

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export class IgxPivotRowExpansionPipe implements PipeTransform {
102102
* @hidden
103103
*/
104104
@Pipe({
105-
name: 'pivotGridMRL',
105+
name: 'pivotGridCellMerging',
106106
pure: true
107107
})
108-
export class IgxPivotRowMRLPipe implements PipeTransform {
108+
export class IgxPivotCellMergingPipe implements PipeTransform {
109109
constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
110110
public transform(
111111
collection: any[],
@@ -114,22 +114,30 @@ export class IgxPivotRowMRLPipe implements PipeTransform {
114114
_pipeTrigger?: number
115115
): any[] {
116116
if (collection.length === 0 || config.rows.length === 0) return collection;
117-
let data = [];
117+
const data = collection ? cloneArray(collection, true) : [];
118118
let groupData = [];
119119
let prev;
120-
const dim = config.rows[0];
121-
for (let rec of collection) {
122-
const dimData = PivotUtil.getDimensionLevel(dim, rec, pivotKeys);
123-
const val = rec[dimData.dimension.memberName];
124-
if (prev !== val && groupData.length > 0) {
125-
groupData[0][dim.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.children] = groupData;
126-
if (data.indexOf(groupData[0]) === -1) {
127-
data.push(groupData[0]);
120+
let prevDim;
121+
let prevDimRoot;
122+
const enabledRows = config.rows.filter(x => x.enabled);
123+
for (let dim of enabledRows) {
124+
for (let rec of data) {
125+
const dimData = PivotUtil.getDimensionLevel(dim, rec, pivotKeys);
126+
const val = rec[dimData.dimension.memberName];
127+
if (prev !== val && groupData.length > 0) {
128+
groupData.forEach((gr, ind) => {
129+
if (ind === 0) {
130+
gr[prevDim.dimension.memberName + pivotKeys.rowDimensionSeparator + 'first'] = true;
131+
}
132+
gr[prevDim.dimension.memberName + pivotKeys.rowDimensionSeparator + 'rowSpan'] = groupData.length;
133+
});
134+
groupData = [];
128135
}
129-
groupData = [];
136+
groupData.push(rec);
137+
prev = val;
138+
prevDim = dimData;
139+
prevDimRoot = dim;
130140
}
131-
groupData.push(rec);
132-
prev = val;
133141
}
134142
return data;
135143
}

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-row-dimension-content.component.html

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
<div role="rowgroup" class="igx-grid-thead__wrapper" [style.width.px]="width"
1+
<div role="rowgroup" class="igx-grid-thead__wrapper" [style.width.px]="width"
22
[class.igx-grid__tr--mrl]="hasMRL">
33
<div class="igx-grid__tr" role="row" [style.width.px]="width">
4-
<ng-template ngFor #headerVirtualContainer let-column
5-
[ngForOf]="rowDimension">
6-
<igx-pivot-row-dimension-header-group [ngClass]="column.headerGroupClasses"
7-
[ngStyle]="column.headerGroupStyles |igxHeaderGroupStyle:column:grid.pipeTrigger" [column]="column"
8-
[style.min-width]="column.calcWidth | igxHeaderGroupWidth:grid.defaultHeaderGroupMinWidth:hasMRL"
9-
[style.flex-basis]="column.calcWidth | igxHeaderGroupWidth:grid.defaultHeaderGroupMinWidth:hasMRL"
10-
[rowIndex]="rowIndex">
4+
<igx-pivot-row-dimension-header-group *ngIf='isFirst' [ngClass]="rowDimensionColumn.headerGroupClasses"
5+
[ngStyle]="rowDimensionColumn.headerGroupStyles |igxHeaderGroupStyle:rowDimensionColumn:grid.pipeTrigger" [column]="rowDimensionColumn"
6+
[style.min-width]="rowDimensionColumn.calcWidth | igxHeaderGroupWidth:grid.defaultHeaderGroupMinWidth:hasMRL"
7+
[style.flex-basis]="rowDimensionColumn.calcWidth | igxHeaderGroupWidth:grid.defaultHeaderGroupMinWidth:hasMRL"
8+
[rowIndex]="rowIndex"
9+
[style.min-height.px]='headerHeight'>
1110
</igx-pivot-row-dimension-header-group>
12-
</ng-template>
1311
</div>
1412
</div>
1513

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-row-dimension-content.component.ts

Lines changed: 51 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
4141
@Input()
4242
public rowIndex: number;
4343

44+
@Input()
45+
public dimension: IPivotDimension;
46+
4447
@Input()
4548
public rowData: any;
4649

@@ -65,10 +68,10 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
6568
) {
6669
super(ref, cdr);
6770
}
68-
protected rowDimensionData: IPivotDimensionData[] = [];
71+
protected rowDimensionData: IPivotDimensionData;
6972

70-
public get rowDimension() {
71-
return this.rowDimensionData?.filter(x => !x.isChild).map(x => x.column);
73+
public get rowDimensionColumn() {
74+
return this.rowDimensionData?.column;
7275
}
7376

7477
/**
@@ -77,19 +80,17 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
7780
*/
7881
public ngOnChanges(changes: SimpleChanges) {
7982
const rowDimConfig = this.grid.rowDimensions;
80-
if (changes.data || rowDimConfig.length !== this.rowDimensionData.length) {
83+
if (changes.rowData) {
8184
// generate new rowDimension on row data change
82-
this.rowDimensionData = [];
85+
this.rowDimensionData = null;
8386
this.viewRef.clear();
84-
this.extractFromDimensions(rowDimConfig, 0);
87+
this.extractFromDimensions();
8588
this.viewRef.clear();
8689
}
8790
if (changes.pivotRowWidths && this.rowDimensionData) {
88-
for (const dim of rowDimConfig) {
89-
const dimData = PivotUtil.getDimensionLevel(dim, this.rowData, this.grid.pivotKeys);
90-
const data = this.rowDimensionData.find(x => x.dimension.memberName === dimData.dimension.memberName);
91-
data.column.width = this.grid.resolveRowDimensionWidth(dim) + 'px';
92-
}
91+
const dimData = PivotUtil.getDimensionLevel(this.dimension, this.rowData, this.grid.pivotKeys);
92+
const data = this.rowDimensionData;
93+
data.column.width = this.grid.resolveRowDimensionWidth(this.dimension) + 'px';
9394
}
9495
}
9596

@@ -99,7 +100,7 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
99100
* @internal
100101
*/
101102
public getRowDimensionKey(col: IgxColumnComponent) {
102-
const dimData = this.rowDimensionData.find(x => x.column.field === col.field);
103+
const dimData = this.rowDimensionData;
103104
const key = PivotUtil.getRecordKey(this.rowData, dimData.dimension, dimData.prevDimensions, this.grid.pivotKeys);
104105
return key;
105106
}
@@ -112,6 +113,19 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
112113
return this.rowData[col.field + this.grid.pivotKeys.rowDimensionSeparator + this.grid.pivotKeys.level];
113114
}
114115

116+
get rowSpan() {
117+
return this.rowData[this.rowDimensionData.dimension.memberName + this.grid.pivotKeys.rowDimensionSeparator + 'rowSpan'] || 1;
118+
}
119+
120+
get headerHeight() {
121+
return this.rowSpan * this.grid.renderedRowHeight;
122+
}
123+
124+
get isFirst() {
125+
const hasRowSpan = this.rowSpan && this.rowSpan > 1;
126+
return !hasRowSpan || this.rowData[this.rowDimensionData.dimension.memberName + this.grid.pivotKeys.rowDimensionSeparator + 'first'];
127+
}
128+
115129

116130
/**
117131
* @hidden @internal
@@ -129,91 +143,41 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
129143
}
130144
}
131145

132-
protected extractFromDimensions(rowDimConfig: IPivotDimension[], level: number) {
133-
let dimIndex = 0;
134-
let currentLvl = 0;
135-
currentLvl += level;
136-
const prev = [];
137-
let prevDim;
138-
for (const dim of rowDimConfig) {
139-
const dimData = PivotUtil.getDimensionLevel(dim, this.rowData, this.grid.pivotKeys);
140-
dimIndex += dimData.level;
141-
currentLvl += dimData.level;
142-
const prevChildren = prevDim ? this.rowData[prevDim.memberName + this.grid.pivotKeys.rowDimensionSeparator + this.grid.pivotKeys.children] : [];
143-
if (prevChildren && prevChildren.length > 0) {
144-
const childrenCols = [];
145-
const layoutCol = this.rowDimensionData.find(x => x.column.columnLayout).column;
146-
prevChildren.forEach((childData, index) => {
147-
const dimData = PivotUtil.getDimensionLevel(dim, childData, this.grid.pivotKeys);
148-
dimIndex += dimData.level;
149-
currentLvl += dimData.level;
150-
const column = this.extractFromDimension(dimData.dimension, childData, [], dimIndex, currentLvl, dim, [...prev]);
151-
column.rowStart = index + 1;
152-
column.rowEnd = index + 2;
153-
column.colStart = 2;
154-
childrenCols.push(column);
155-
this.rowDimensionData.push({
156-
column,
157-
dimension: dimData.dimension,
158-
prevDimensions: [...prev],
159-
isChild: true
160-
});
161-
});
162-
const all_children = layoutCol.children.toArray().concat(childrenCols);
163-
layoutCol.children.reset(all_children);
164-
continue;
165-
}
166-
const children = this.rowData[dim.memberName + this.grid.pivotKeys.rowDimensionSeparator + this.grid.pivotKeys.children];
167-
const column = this.extractFromDimension(dimData.dimension, this.rowData, children, dimIndex, currentLvl, dim, [...prev]);
168-
this.rowDimensionData.push({
169-
column,
170-
dimension: dimData.dimension,
171-
prevDimensions: [...prev]
172-
});
173-
prevDim = dim;
174-
prev.push(dimData.dimension);
146+
protected extractFromDimensions() {
147+
const dimData = PivotUtil.getDimensionLevel(this.dimension, this.rowData, this.grid.pivotKeys);
148+
const col = this.extractFromDimension(dimData, this.rowData);
149+
const prevDims = this.getPrevDims(this.dimension);
150+
this.rowDimensionData = {
151+
column: col,
152+
dimension: dimData.dimension,
153+
prevDimensions: prevDims
154+
};
155+
}
156+
157+
protected getPrevDims(currDim) {
158+
const ind = this.grid.rowDimensions.indexOf(currDim);
159+
const prevDims = [];
160+
for (let i = 0; i < ind - 1; i++) {
161+
const prevDim = this.grid.rowDimensions[i];
162+
const dimData = PivotUtil.getDimensionLevel(prevDim, this.rowData, this.grid.pivotKeys);
163+
prevDims.push(dimData.dimension);
175164
}
165+
return prevDims;
176166
}
177167

178-
protected extractFromDimension(dim: IPivotDimension, rowData: any[], children: any[], index: number = 0, lvl = 0, rootDim: IPivotDimension, prevDims) {
179-
const field = dim.memberName;
168+
protected extractFromDimension(dimData, rowData: any[]) {
169+
const field = dimData.dimension.memberName;
180170
const header = rowData[field];
181-
let col;
182-
if (children && children.length > 0) {
183-
const ref = this.viewRef.createComponent(IgxColumnLayoutComponent);
184-
col = ref.instance;
185-
ref.instance.field = 'group';
186-
const childCol = this._createColComponent(field, header, children, index, dim, lvl, rootDim);
187-
ref.instance.children.reset([childCol]);
188-
this.rowDimensionData.push({
189-
column: childCol,
190-
dimension: dim,
191-
prevDimensions: prevDims,
192-
isChild: true
193-
});
194-
} else {
195-
col = this._createColComponent(field, header, children, index, dim, lvl, rootDim);
196-
}
171+
const col = this._createColComponent(field, header, dimData.dimension, dimData.level);
197172
return col;
198173
}
199174

200-
protected _createColComponent(field: string, header: string, children: any[],
201-
index: number = 0,
202-
dim: IPivotDimension, lvl = 0, rootDim: IPivotDimension) {
175+
protected _createColComponent(field: string, header: string, dim: IPivotDimension, lvl) {
203176
const ref = this.viewRef.createComponent(IgxColumnComponent);
204-
if (children && children.length > 0) {
205-
ref.instance.rowStart = 1;
206-
ref.instance.rowEnd = children.length + 1;
207-
ref.instance.colStart = 1;
208-
} else {
209-
ref.instance.colStart = 2;
210-
ref.instance.rowStart = 1;
211-
ref.instance.rowEnd = 2;
212-
}
213177
ref.instance.field = field;
214178
ref.instance.header = header;
215-
ref.instance.width = this.grid.resolveRowDimensionWidth(rootDim) + 'px';
216-
(ref as any).instance._vIndex = this.grid.columns.length + index + this.rowIndex * this.grid.pivotConfiguration.rows.length;
179+
ref.instance.width = this.grid.resolveRowDimensionWidth(this.dimension) + 'px';
180+
(ref as any).instance._vIndex = this.grid.columns.length + this.rowIndex + this.rowIndex * this.grid.pivotConfiguration.rows.length;
217181
if (dim.childLevel && lvl >= PivotUtil.getTotalLvl(this.rowData, this.grid.pivotKeys)) {
218182
ref.instance.headerTemplate = this.headerTemplate;
219183
} else {

0 commit comments

Comments
 (0)