Skip to content

Commit a63d1e3

Browse files
MKirovaMKirova
authored andcommitted
Sort columns via column chips.
1 parent f8420b7 commit a63d1e3

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import { GridType } from '../common/grid.interface';
1919
import { IgxGridNavigationService } from '../grid-navigation.service';
2020
import { IgxGridCRUDService } from '../common/crud.service';
2121
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
22-
import { IPivotConfiguration, IPivotKeys, PivotDimensionType } from './pivot-grid.interface';
22+
import { IPivotConfiguration, IPivotDimension, IPivotKeys, PivotDimensionType } from './pivot-grid.interface';
2323
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
2424
import { IgxColumnGroupComponent } from '../columns/column-group.component';
2525
import { IgxColumnComponent } from '../columns/column.component';
2626
import { PivotUtil } from './pivot-util';
2727
import { NoopPivotDimensionsStrategy } from '../../data-operations/pivot-strategy';
28+
import { SortingDirection } from '../../data-operations/sorting-expression.interface';
2829

2930
let NEXT_ID = 0;
3031
const MINIMUM_COLUMN_WIDTH = 200;
@@ -351,7 +352,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
351352
const factoryColumn = this.resolver.resolveComponentFactory(IgxColumnComponent);
352353
const factoryColumnGroup = this.resolver.resolveComponentFactory(IgxColumnGroupComponent);
353354
let columns = [];
354-
fields.forEach((value, key) => {
355+
if (fields.size === 0) {
356+
return columns;
357+
}
358+
const first = fields.keys().next().value;
359+
const dim: IPivotDimension = fields.get(first).dimension;
360+
let currentFields = fields;
361+
if (dim.sortDirection) {
362+
const reverse = (dim.sortDirection === SortingDirection.Desc ? -1 : 1);
363+
currentFields = new Map([...fields.entries()].sort((a, b) => reverse * (a > b ? 1 : a < b ? -1 : 0)));
364+
}
365+
currentFields.forEach((value, key) => {
355366
if (value.children == null || value.children.length === 0 || value.children.size === 0) {
356367
const ref = this.hasMultipleValues ?
357368
factoryColumnGroup.create(this.viewRef.injector) :

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
(dragOver)="onDimDragOver($event, 2)"
1515
(dragLeave)="onDimDragLeave($event)"
1616
(dragDrop)="onDimDrop($event, filterArea, 2)"
17-
(click)="onChipSort($event, filter)"
1817
>
1918
<igx-icon igxPrefix>filter_list</igx-icon>
2019
{{filter.memberName}}
21-
<igx-icon *ngIf="filter.sortDirection" igxSuffix> {{ filter.sortDirection < 2 ? 'arrow_upward' : 'arrow_downward' }}</igx-icon>
2220
</igx-chip>
2321
</igx-chips-area>
2422
</div>
@@ -36,7 +34,7 @@
3634
(dragOver)="onDimDragOver($event, 1)"
3735
(dragLeave)="onDimDragLeave($event)"
3836
(dragDrop)="onDimDrop($event, colArea, 1)"
39-
(click)="onChipSort($event, col)"
37+
(click)="onChipSort($event, col, 1)"
4038
>
4139
<igx-icon igxPrefix>view_column</igx-icon>
4240
<igx-icon igxPrefix>filter_list</igx-icon>
@@ -90,7 +88,7 @@
9088
(dragLeave)="onDimDragLeave($event)"
9189
(dragDrop)="onDimDrop($event, rowArea, 0)"
9290
(dragOver)="onDimDragOver($event, 0)"
93-
(click)="onChipSort($event, row)">
91+
(click)="onChipSort($event, row, 0)">
9492
<igx-icon igxPrefix>table_rows</igx-icon>
9593
<igx-icon igxPrefix>filter_list</igx-icon>
9694
{{ row.memberName}}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
7676
filter.enabled = false;
7777
}
7878

79-
public onChipSort(event, dimension: IPivotDimension) {
79+
public onChipSort(event, dimension: IPivotDimension, dimensionType: PivotDimensionType) {
8080
if (!dimension.sortDirection) {
8181
dimension.sortDirection = SortingDirection.None;
8282
}
@@ -89,6 +89,9 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
8989
dim = dim.childLevel;
9090
}
9191
this.grid.pipeTrigger++;
92+
if (dimensionType === PivotDimensionType.Column) {
93+
this.grid.setupColumns();
94+
}
9295
}
9396

9497
public onDimDragOver(event, dimension?: PivotDimensionType) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class PivotUtil {
156156
const value = this.extractValueFromDimension(col, recData);
157157
path.push(value);
158158
const newValue = path.join('-');
159-
lvlCollection.push({ value: newValue });
159+
lvlCollection.push({ value: newValue, dimension: col });
160160
lvlCollection[0].expandable = col.expandable;
161161
if (!lvlCollection[0].children) {
162162
lvlCollection[0].children = [];

src/app/pivot-grid/pivot-grid.sample.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ export class PivotGridSampleComponent {
2323

2424
public pivotConfigHierarchy: IPivotConfiguration = {
2525
columns: [
26-
2726
{
28-
memberName: 'Country',
29-
enabled: true
27+
memberName: 'AllCountries',
28+
memberFunction: () => 'AllCountries',
29+
enabled: true,
30+
childLevel: {
31+
memberName: 'Country',
32+
enabled: true
33+
}
3034
}
3135
]
3236
,

0 commit comments

Comments
 (0)