Skip to content

Commit 99f0bde

Browse files
hanastasovzdrawkurkaraivanov
authored
Update grid view via dataMapper pipe on value change (#8519)
* fix(grid): invoke dataMapper on value change #8424 Co-authored-by: Zdravko Kolev <[email protected]> Co-authored-by: Radoslav Karaivanov <[email protected]>
1 parent 078480a commit 99f0bde

19 files changed

+1983
-13
lines changed

projects/igniteui-angular/src/lib/grids/common/pipes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class IgxSortActionColumnsPipe implements PipeTransform {
268268
@Pipe({ name: 'dataMapper' })
269269
export class IgxGridDataMapperPipe implements PipeTransform {
270270

271-
transform(data: any[], field: string, _: number) {
271+
transform(data: any[], field: string, _: number, __: any) {
272272
return resolveNestedPath(data, field);
273273
}
274274
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
[style.left]="col.rightPinnedOffset"
120120
[width]="col.getCellWidth()"
121121
[visibleColumnIndex]="col.visibleIndex"
122-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
122+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
123123
[cellTemplate]="col.bodyTemplate"
124124
[lastSearchInfo]="grid.lastSearchInfo"
125125
[active]="isCellActive(col.visibleIndex)"
@@ -151,7 +151,7 @@
151151
[style.flex-basis]="col.width"
152152
[width]="col.getCellWidth()"
153153
[visibleColumnIndex]="col.visibleIndex"
154-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
154+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
155155
[cellTemplate]="col.bodyTemplate"
156156
[lastSearchInfo]="grid.lastSearchInfo"
157157
[active]="isCellActive(col.visibleIndex)"
@@ -187,7 +187,7 @@
187187
[style.min-height.px]="cellHeight"
188188
[rowData]="rowData"
189189
[visibleColumnIndex]="col.visibleIndex"
190-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
190+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
191191
[cellTemplate]="col.bodyTemplate"
192192
[lastSearchInfo]="grid.lastSearchInfo"
193193
[active]="isCellActive(col.visibleIndex)"
@@ -223,7 +223,7 @@
223223
[style.min-height.px]="cellHeight"
224224
[rowData]="rowData"
225225
[visibleColumnIndex]="col.visibleIndex"
226-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
226+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
227227
[cellTemplate]="col.bodyTemplate"
228228
[lastSearchInfo]="grid.lastSearchInfo"
229229
[active]="isCellActive(col.visibleIndex)"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
[style.flex-basis]="col.width"
6868
[width]="col.getCellWidth()"
6969
[visibleColumnIndex]="col.visibleIndex"
70-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
70+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
7171
[cellTemplate]="col.bodyTemplate"
7272
[lastSearchInfo]="grid.lastSearchInfo"
7373
[cellSelectionMode]="grid.cellSelection"
@@ -116,7 +116,7 @@
116116
[style.left]="col.rightPinnedOffset"
117117
[width]="col.getCellWidth()"
118118
[visibleColumnIndex]="col.visibleIndex"
119-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
119+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
120120
[cellTemplate]="col.bodyTemplate"
121121
[lastSearchInfo]="grid.lastSearchInfo"
122122
[cellSelectionMode]="grid.cellSelection"

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
[style.flex-basis]="col.width"
4444
[width]="col.getCellWidth()"
4545
[visibleColumnIndex]="col.visibleIndex"
46-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
46+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
4747
[cellTemplate]="col.bodyTemplate"
4848
[lastSearchInfo]="grid.lastSearchInfo"
4949
[active]="isCellActive(col.visibleIndex)"
@@ -74,7 +74,7 @@
7474
[style.flex-basis]="col.width"
7575
[width]="col.getCellWidth()"
7676
[visibleColumnIndex]="col.visibleIndex"
77-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
77+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
7878
[isLoading]="isLoading"
7979
[cellTemplate]="col.bodyTemplate"
8080
[lastSearchInfo]="grid.lastSearchInfo"
@@ -127,7 +127,7 @@
127127
[style.left]="col.rightPinnedOffset"
128128
[width]="col.getCellWidth()"
129129
[visibleColumnIndex]="col.visibleIndex"
130-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
130+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
131131
[cellTemplate]="col.bodyTemplate"
132132
[lastSearchInfo]="grid.lastSearchInfo"
133133
[active]="isCellActive(col.visibleIndex)"
@@ -160,7 +160,7 @@
160160
[style.left]="col.rightPinnedOffset"
161161
[width]="col.getCellWidth()"
162162
[visibleColumnIndex]="col.visibleIndex"
163-
[value]="rowData | dataMapper:col.field:grid.pipeTrigger"
163+
[value]="rowData | dataMapper:col.field:grid.pipeTrigger:rowData[col.field]"
164164
[isLoading]="isLoading"
165165
[cellTemplate]="col.bodyTemplate"
166166
[lastSearchInfo]="grid.lastSearchInfo"
@@ -172,5 +172,4 @@
172172
</ng-template>
173173
<ng-container *ngTemplateOutlet="col.visibleIndex === 0 ? treeCellTemplate : cellTemplate"></ng-container>
174174
</ng-template>
175-
</ng-template>
176175
</ng-template>

src/app/app.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ export class AppComponent implements OnInit {
258258
icon: 'view_column',
259259
name: 'Grid Formatting'
260260
},
261+
{
262+
link: '/gridFinJS',
263+
icon: 'view_column',
264+
name: 'Grid FinJS'
265+
},
261266
{
262267
link: '/gridRemoteVirtualization',
263268
icon: 'view_column',

src/app/app.module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ import { IgxColumnGroupingDirective } from './grid-column-actions/custom-action-
137137
import { GridAddRowSampleComponent } from './grid-add-row/grid-add-row.sample';
138138
import { HierarchicalGridAddRowSampleComponent } from './hierarchical-grid-add-row/hierarchical-grid-add-row.sample';
139139
import { GridFormattingComponent } from './grid-formatting/grid-formatting.component';
140+
import { GridFinJSComponent } from './grid-finjs/grid-finjs.component';
141+
import { MainComponent } from './grid-finjs/main.component';
142+
import { ControllerComponent } from './grid-finjs/controllers.component';
143+
import { CommonModule } from '@angular/common';
140144

141145
const components = [
142146
ActionStripSampleComponent,
@@ -250,6 +254,9 @@ const components = [
250254
GridEsfLoadOnDemandComponent,
251255
GridFilteringComponent,
252256
GridFormattingComponent,
257+
GridFinJSComponent,
258+
MainComponent,
259+
ControllerComponent,
253260
GridExternalFilteringComponent,
254261
GridSaveStateComponent,
255262
AboutComponent,
@@ -268,6 +275,7 @@ const components = [
268275
BrowserAnimationsModule,
269276
HammerModule,
270277
FormsModule,
278+
CommonModule,
271279
ReactiveFormsModule,
272280
HttpClientModule,
273281
IgxIconModule,

src/app/app.routing.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import { GridColumnActionsSampleComponent } from './grid-column-actions/grid-col
8080
import { GridAddRowSampleComponent } from './grid-add-row/grid-add-row.sample';
8181
import { HierarchicalGridAddRowSampleComponent } from './hierarchical-grid-add-row/hierarchical-grid-add-row.sample';
8282
import { GridFormattingComponent } from './grid-formatting/grid-formatting.component';
83+
import { MainComponent } from './grid-finjs/main.component';
8384

8485
const appRoutes = [
8586
{
@@ -388,6 +389,10 @@ const appRoutes = [
388389
{
389390
path: 'gridFormatting',
390391
component: GridFormattingComponent
392+
},
393+
{
394+
path: 'gridFinJS',
395+
component: MainComponent
391396
}
392397
];
393398

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div class="controls-wrapper">
2+
<div class="controls-holder">
3+
<div class="switches">
4+
<div class="control-item">
5+
<igx-switch [checked]="true" [(ngModel)]="theme" (change)="onChange('theme', $event)">Dark</igx-switch>
6+
</div>
7+
<div class="control-item">
8+
<igx-switch [checked]="grouped" (change)="onChange('grouped', $event)" color="blue" cssClass="finjs-sample-switch">
9+
Grouped</igx-switch>
10+
</div>
11+
<div class="control-item">
12+
<igx-switch (change)="onChange('toolbar', $event)" color="blue" cssClass="finjs-sample-switch">Toolbar</igx-switch>
13+
</div>
14+
<div class="finjs-slider control-item">
15+
<label for="slider">Records: {{volume}}</label>
16+
<igx-slider #slider1 id="slider" [minValue]="0" [maxValue]="10000" [(ngModel)]="volume" [step]="100" thumbLabelVisibilityDuration="250" [continuous]="true"></igx-slider>
17+
</div>
18+
<div class="finjs-slider control-item">
19+
<label for="slider">Frequency: {{frequency}} ms</label>
20+
<igx-slider #slider2 id="slider" [minValue]="100" [maxValue]="3000" [step]="10" [(ngModel)]="frequency" thumbLabelVisibilityDuration="250" [continuous]="true"></igx-slider>
21+
</div>
22+
</div>
23+
<div class="control-item finjs-play-controls">
24+
<igx-buttongroup class="finjssample-btn-group" #buttonGroup1 [multiSelection]="false" [values]="controls" (onSelect)="onButtonSelected($event)"></igx-buttongroup>
25+
</div>
26+
</div>
27+
<div class="sample-toolbar">
28+
<span *ngIf="buttonSelected === 1">Feeding {{volume}} records every {{frequency / 1000}} sec.
29+
{{volume}} records updated. </span>
30+
<span *ngIf="buttonSelected === 0">Feeding {{volume}} records every {{frequency / 1000}} sec.
31+
~{{volume/5}} records updated.</span>
32+
</div>
33+
</div>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
:host ::ng-deep {
2+
.fin-dark-theme {
3+
.finjs-slider,
4+
.sample-toolbar {
5+
color: rgba(255, 255, 255, 0.87);
6+
}
7+
}
8+
9+
.controls-holder {
10+
display: flex;
11+
justify-content: space-between;
12+
align-items: center;
13+
flex-wrap: wrap;
14+
width: 100%;
15+
padding-bottom: 15px;
16+
}
17+
.switches {
18+
display: flex;
19+
justify-content: space-between;
20+
align-items: center;
21+
flex: 1 0 0%;
22+
padding-right: 20px;
23+
font-size: 0.9rem;
24+
}
25+
.control-item {
26+
padding-right: 20px;
27+
label {
28+
color: var(--igx-surface-500-contrast);
29+
}
30+
}
31+
.igx-slider,
32+
.igx-slider--disabled {
33+
height: 24px;
34+
}
35+
.finjs-slider {
36+
width: 40%;
37+
min-width: 145px;
38+
}
39+
.finjs-play-controls {
40+
width: 45%;
41+
min-width: 620px;
42+
margin-top: 10px;
43+
}
44+
.sample-toolbar {
45+
height: 20px;
46+
font-size: 0.8rem;
47+
line-height: 20px;
48+
/* position: absolute; */
49+
/* bottom: 10px; */
50+
/* left: 10px; */
51+
margin-top: 11px;
52+
}
53+
.igx-button--icon {
54+
width: 2rem;
55+
height: 2rem;
56+
}
57+
}
58+
59+
.controls-wrapper {
60+
display: flex;
61+
justify-content: center;
62+
position: relative;
63+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
2+
import { IgxButtonGroupComponent, IgxSliderComponent,
3+
} from 'igniteui-angular';
4+
import { timer } from 'rxjs';
5+
import { debounce } from 'rxjs/operators';
6+
7+
@Component({
8+
selector: 'app-finjs-controllers',
9+
styleUrls: ['./controllers.component.scss'],
10+
templateUrl: './controllers.component.html'
11+
})
12+
export class ControllerComponent implements OnInit, OnDestroy {
13+
@ViewChild('buttonGroup1', { static: true }) public buttonGroup1: IgxButtonGroupComponent;
14+
@ViewChild('buttonGroup2', { static: true }) public buttonGroup2: IgxButtonGroupComponent;
15+
@ViewChild('slider1', { static: true }) public volumeSlider: IgxSliderComponent;
16+
@ViewChild('slider2', { static: true }) public intervalSlider: IgxSliderComponent;
17+
18+
@Output() public switchChanged = new EventEmitter<any>();
19+
@Output() public volumeChanged = new EventEmitter<any>();
20+
@Output() public frequencyChanged = new EventEmitter<any>();
21+
@Output() public playAction = new EventEmitter<any>();
22+
23+
public selectionMode = 'multiple';
24+
public theme = false;
25+
public volume = 1000;
26+
public frequency = 500;
27+
public grouped = true;
28+
public controls = [
29+
{
30+
disabled: false,
31+
icon: 'update',
32+
label: 'LIVE PRICES',
33+
selected: false
34+
},
35+
{
36+
disabled: false,
37+
icon: 'update',
38+
label: 'LIVE ALL PRICES',
39+
selected: false
40+
},
41+
{
42+
disabled: true,
43+
icon: 'stop',
44+
label: 'Stop',
45+
selected: false
46+
}
47+
];
48+
49+
private subscription;
50+
private selectedButton;
51+
private volumeChanged$;
52+
53+
public ngOnInit() {
54+
this.volumeChanged$ = this.volumeSlider.onValueChange.pipe(debounce(() => timer(200)));
55+
this.volumeChanged$.subscribe(x => this.volumeChanged.emit(this.volumeSlider.value));
56+
}
57+
58+
public onButtonSelected(event: any) {
59+
switch (event.index) {
60+
case 0: {
61+
this.disableOtherButtons(event.index, true);
62+
this.playAction.emit({ action: 'playRandom'} );
63+
break;
64+
}
65+
case 1: {
66+
this.disableOtherButtons(event.index, true);
67+
this.playAction.emit({ action: 'playAll'} );
68+
break;
69+
}
70+
case 2: {
71+
this.disableOtherButtons(event.index, false);
72+
this.playAction.emit({ action: 'stop'} );
73+
break;
74+
}
75+
case 3: {
76+
this.disableOtherButtons(event.index, true);
77+
break;
78+
}
79+
default:
80+
{
81+
break;
82+
}
83+
}
84+
}
85+
86+
public onChange(action: string, event: any) {
87+
this.switchChanged.emit({action, value: event.checked });
88+
}
89+
90+
private disableOtherButtons(ind: number, disableButtons: boolean) {
91+
if (this.subscription) {
92+
this.subscription.unsubscribe();
93+
}
94+
this.volumeSlider.disabled = disableButtons;
95+
this.intervalSlider.disabled = disableButtons;
96+
this.selectedButton = ind;
97+
this.buttonGroup1.buttons.forEach((button, index) => {
98+
if (index === 2) { button.disabled = !disableButtons; } else {
99+
this.buttonGroup1.buttons[0].disabled = disableButtons;
100+
this.buttonGroup1.buttons[1].disabled = disableButtons;
101+
}
102+
});
103+
}
104+
105+
get buttonSelected(): number {
106+
return this.selectedButton || this.selectedButton === 0 ? this.selectedButton : -1;
107+
}
108+
109+
public ngOnDestroy() {
110+
this.volumeChanged$.unsubscribe();
111+
}
112+
}

0 commit comments

Comments
 (0)