Skip to content

Commit 7c2fb71

Browse files
authored
Merge pull request #3051 from IgniteUI/ikitanov/fix-3042
fix(grid-selection):Updating the use of rowSelectionChanging event in…
2 parents 1275c4c + 171f7dc commit 7c2fb71

9 files changed

Lines changed: 99 additions & 9 deletions

src/app/grid/grid-sample-selection/grid-selection.component.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@
4949
</igx-grid>
5050
</div>
5151

52+
<igx-snackbar #snackbarRowCount actionText="Got it. Thanks!" (clicked)="snackbarRowCount.close()">
53+
<div class="container">
54+
<igx-icon>notification_important</igx-icon>
55+
<ng-container *ngIf="selectionMode === 'multiple'">
56+
<p>Number of selected rows: {{selectedRowsCount}}</p>
57+
</ng-container>
58+
<ng-container *ngIf="selectionMode === 'single' && this.selectedRowIndex !== undefined">
59+
<p>Currently selected row index: {{selectedRowIndex}}</p>
60+
</ng-container>
61+
<ng-container *ngIf="selectionMode === 'single' && this.selectedRowIndex === undefined">
62+
<p>There is no currently selected row.</p>
63+
</ng-container>
64+
</div>
65+
</igx-snackbar>
66+
5267
<igx-snackbar #snackbar actionText="Got it. Thanks!" (clicked)="snackbar.close()">
5368
<div class="container">
5469
<igx-icon>notification_important</igx-icon>

src/app/grid/grid-sample-selection/grid-selection.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ ul {
5858
margin: 20px;
5959
}
6060
}
61+
62+
.container p {
63+
margin-top: 20px;
64+
}

src/app/grid/grid-sample-selection/grid-selection.component.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit, ViewChild } from '@angular/core';
22

3-
import { IgxGridComponent, IgxSnackbarComponent } from 'igniteui-angular';
3+
import { IgxGridComponent, IgxSnackbarComponent, IRowSelectionEventArgs } from 'igniteui-angular';
44
import { Observable } from 'rxjs';
55
import { FinancialDataService } from '../../services/financial.service';
66

@@ -15,12 +15,15 @@ import { FinancialDataService } from '../../services/financial.service';
1515

1616
export class GridSelectionSampleComponent implements OnInit {
1717
@ViewChild('grid1', { static: true }) public grid1: IgxGridComponent;
18-
@ViewChild(IgxSnackbarComponent, { static: true }) public snackbar: IgxSnackbarComponent;
18+
@ViewChild('snackbarRowCount', { static: true }) public snackbarRowCount: IgxSnackbarComponent;
19+
@ViewChild('snackbar', { static: true }) public snackbar: IgxSnackbarComponent;
1920
public data: Observable<any[]>;
2021
public selectionMode = 'multiple';
2122
public selectionModes = [];
2223
public hideRowSelectors = false;
2324
public selectedRows = [1, 2, 3];
25+
public selectedRowsCount;
26+
public selectedRowIndex;
2427

2528
constructor(private localService: FinancialDataService) {
2629
this.localService.getData(100000);
@@ -35,20 +38,27 @@ export class GridSelectionSampleComponent implements OnInit {
3538
public ngOnInit(): void {
3639
this.snackbar.autoHide = false;
3740
this.snackbar.open();
41+
this.snackbarRowCount.autoHide = true;
42+
this.snackbarRowCount.close();
3843
}
39-
4044
public formatNumber(value: number) {
4145
return value.toFixed(2);
4246
}
4347
public formatCurrency(value: number) {
4448
return '$' + value.toFixed(2);
4549
}
46-
public handleRowSelection(event) {
47-
const targetCell = event.cell;
50+
public handleRowSelection(event:IRowSelectionEventArgs) {
51+
this.selectedRowsCount = event.newSelection.length;
52+
this.selectedRowIndex = event.newSelection[0];
53+
this.snackbarRowCount.open();
54+
this.snackbar.close();
4855
}
4956

5057
public selectCellSelectionMode(args) {
5158
this.selectionMode = this.selectionModes[args.index].label;
5259
this.snackbar.open();
60+
this.snackbarRowCount.close();
61+
this.selectedRowsCount = undefined;
62+
this.selectedRowIndex = undefined;
5363
}
5464
}

src/app/hierarchical-grid/hierarchical-grid-selection/hierarchical-grid-selection.component.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@
4040
</igx-hierarchical-grid>
4141
</div>
4242

43+
<igx-snackbar #snackbarRowCount actionText="Got it. Thanks!" (clicked)="snackbarRowCount.close()">
44+
<div class="container">
45+
<igx-icon>notification_important</igx-icon>
46+
<ng-container *ngIf="selectionMode === 'multiple'">
47+
<p>Number of selected rows: {{selectedRowsCount}}</p>
48+
</ng-container>
49+
<ng-container *ngIf="selectionMode === 'single' && this.selectedRowIndex !== undefined">
50+
<p>Currently selected row index: {{selectedRowIndex}}</p>
51+
</ng-container>
52+
<ng-container *ngIf="selectionMode === 'single' && this.selectedRowIndex === undefined">
53+
<p>There is no currently selected row.</p>
54+
</ng-container>
55+
</div>
56+
</igx-snackbar>
57+
4358
<igx-snackbar #snackbar actionText="Got it. Thanks!" (clicked)="snackbar.close()">
4459
<div class="container">
4560
<igx-icon>notification_important</igx-icon>

src/app/hierarchical-grid/hierarchical-grid-selection/hierarchical-grid-selection.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@
3232
margin: 20px;
3333
}
3434
}
35+
36+
.container p {
37+
margin-top: 20px;
38+
}

src/app/hierarchical-grid/hierarchical-grid-selection/hierarchical-grid-selection.component.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import { SINGERS } from '../../data/singersData';
99
})
1010

1111
export class HGridSelectionSampleComponent implements OnInit {
12-
@ViewChild(IgxSnackbarComponent, { static: true }) public snackbar: IgxSnackbarComponent;
12+
@ViewChild('snackbarRowCount', { static: true }) public snackbarRowCount: IgxSnackbarComponent;
13+
@ViewChild('snackbar', { static: true }) public snackbar: IgxSnackbarComponent;
1314
public localdata;
1415
public selectionMode = 'multiple';
1516
public selectionModes = [];
1617
public hideRowSelectors = false;
18+
public selectedRowsCount;
19+
public selectedRowIndex;
1720

1821
constructor() {
1922
this.localdata = SINGERS;
@@ -30,11 +33,20 @@ export class HGridSelectionSampleComponent implements OnInit {
3033

3134
public selectCellSelectionMode(args) {
3235
this.selectionMode = this.selectionModes[args.index].label;
36+
this.snackbarRowCount.close();
3337
this.snackbar.open();
38+
this.selectedRowsCount = undefined;
39+
this.selectedRowIndex = undefined;
3440
}
3541

3642
public handleRowSelection(event) {
37-
const targetCell = event.cell;
43+
this.selectedRowsCount = event.newSelection.length;
44+
if(event.newSelection.length > 0){
45+
this.selectedRowIndex = event.newSelection[0].ID;
46+
}
47+
else this.selectedRowIndex = undefined;
48+
this.snackbarRowCount.open();
49+
this.snackbar.close();
3850
}
3951

4052
public formatter = (a) => a;

src/app/tree-grid/tree-grid-selection-sample/tree-grid-selection-sample.component.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
</igx-tree-grid>
1515
</div>
1616

17+
<igx-snackbar #snackbarRowCount actionText="Got it. Thanks!" (clicked)="snackbarRowCount.close()">
18+
<div class="container">
19+
<igx-icon>notification_important</igx-icon>
20+
<ng-container *ngIf="selectionMode === 'multiple' || selectionMode === 'multipleCascade'">
21+
<p>Number of selected rows: {{selectedRowsCount}}</p>
22+
</ng-container>
23+
<ng-container *ngIf="selectionMode === 'single' && this.selectedRowIndex !== undefined">
24+
<p>Currently selected row index: {{selectedRowIndex}}</p>
25+
</ng-container>
26+
<ng-container *ngIf="selectionMode === 'single' && this.selectedRowIndex === undefined">
27+
<p>There is no currently selected row.</p>
28+
</ng-container>
29+
</div>
30+
</igx-snackbar>
31+
1732
<igx-snackbar #snackbar actionText="Got it. Thanks!" (clicked)="snackbar.close()">
1833
<div class="container">
1934
<igx-icon>notification_important</igx-icon>

src/app/tree-grid/tree-grid-selection-sample/tree-grid-selection-sample.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ igx-buttongroup {
2727
margin: 20px;
2828
}
2929
}
30+
31+
.container p {
32+
margin-top: 20px;
33+
}

src/app/tree-grid/tree-grid-selection-sample/tree-grid-selection-sample.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import { generateEmployeeFlatData } from '../data/employees-flat';
99
})
1010
export class TreeGridSelectionSampleComponent implements OnInit {
1111
@ViewChild('treeGrid', { static: true }) public treeGrid: IgxTreeGridComponent;
12-
@ViewChild(IgxSnackbarComponent, { static: true }) public snackbar: IgxSnackbarComponent;
12+
@ViewChild('snackbarRowCount', { static: true }) public snackbarRowCount: IgxSnackbarComponent;
13+
@ViewChild('snackbar', { static: true }) public snackbar: IgxSnackbarComponent;
1314
public data: any[];
1415
public selectionMode = 'multiple';
1516
public selectionModes = [];
1617
public hideRowSelectors = false;
1718
public selectedRows = [1, 2, 3];
19+
public selectedRowsCount;
20+
public selectedRowIndex;
1821

1922
constructor() {
2023
this.data = generateEmployeeFlatData();
@@ -32,10 +35,18 @@ export class TreeGridSelectionSampleComponent implements OnInit {
3235
this.snackbar.open();
3336
}
3437

35-
public handleRowSelection(event) { }
38+
public handleRowSelection(event) {
39+
this.selectedRowsCount = event.newSelection.length;
40+
this.selectedRowIndex = event.newSelection[0];
41+
this.snackbarRowCount.open();
42+
this.snackbar.close();
43+
}
3644

3745
public selectCellSelectionMode(args) {
3846
this.selectionMode = this.selectionModes[args.index].selectMode;
47+
this.snackbarRowCount.close();
3948
this.snackbar.open();
49+
this.selectedRowsCount = undefined;
50+
this.selectedRowIndex = undefined;
4051
}
4152
}

0 commit comments

Comments
 (0)