Skip to content

Commit d419a24

Browse files
MKirovaMKirova
authored andcommitted
Merge branch 'mkirova/fix-6540-master' of https://github.com/IgniteUI/igniteui-angular.git
2 parents 09c9c2e + dd535ca commit d419a24

33 files changed

+362
-470
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ All notable changes for each version of this project will be documented in this
1717
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
1818
- **Breaking Change** - Hierarchical grid children no longer use the same `IgxTransactionService` instance and transaction handling should be modified to address each grid's transactions separately.
1919
- **Behavioral Change** - Pinning columns is no longer automatically prevented when the pinning area would exceed the size of the grid.
20+
- **Breaking Change** - The following input and output have been deprecated for the `igxHierarchicalGrid` and will be removed in future versions:
21+
- `hierarchicalState` -> `expansionStates` should be used instead.
22+
- `hierarchicalStateChange` -> `expansionStatesChange` should be used instead.
23+
2024
- `igxGridState` directive added to make it easy for developers to save and restore the grid state. The directive exposes the `getState` and `setState` methods to save/restore the state and an `options` input property to exclude features.
2125
- `IgxCarousel`:
2226
- **Breaking Changes** -The carousel slides are no longer array, they are changed to QueryList.
@@ -41,6 +45,8 @@ All notable changes for each version of this project will be documented in this
4145
- `collapsibleIndicatorTemplate` property is introduced to IgxColumnGroupComponent, which allows you to set a custom template for the expand collapse indicator;
4246
- `igxCollapsibleIndicator` directive has been introduced, which allows you to set a custom template for the expand collapse indicator;
4347
- `IgxGridExcelStyleFilteringComponent` and `IgxAdvancedFilteringDialogComponent` can now be hosted outside of the grid in order to provide the same experience as the built-in filtering UI.
48+
- `expandRow(rowID)`/`collapseRow(rowID)`/`toggleRow(rowID)` API methods are added for the `igxHierarchicalGrid`. They allow expanding/collapsing a row by its id.
49+
- `onRowToggle` event is added for the `igxHierarchicalGrid`. It is emitted when the expanded state of a row is changed.
4450
- `IgxOverlayService`:
4551
- `setOffset` method added. It offsets the content along the corresponding axis by the provided amount.
4652
- `IgxToggleDirective`:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
419419
});
420420
const destructor = takeUntil<any>(this.destroy$);
421421
this.contentResizeNotify.pipe(destructor,
422-
filter(() => this.igxForContainerSize && this.igxForOf && this.igxForOf.length > 0), throttleTime(40))
422+
filter(() => this.igxForContainerSize && this.igxForOf && this.igxForOf.length > 0),
423+
throttleTime(40, undefined, {leading: true, trailing: true}))
423424
.subscribe(() => {
424425
this._zone.runTask(() => {
425426
this.updateSizes();

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Transaction, TransactionType, State } from '../services/transaction/tra
1313
import { IgxCell, IgxRow } from './selection/selection.service';
1414
import { GridType } from './common/grid.interface';
1515
import { ColumnType } from './common/column.interface';
16+
import { IRowToggleEventArgs } from './common/events';
1617
/**
1718
*@hidden
1819
*/
@@ -538,4 +539,53 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
538539
public atInexistingPage(): boolean {
539540
return this.grid.totalPages - 1 > this.grid.page;
540541
}
542+
543+
public get_row_expansion_state(record: any): boolean {
544+
const grid = this.grid;
545+
const states = grid.expansionStates;
546+
const rowID = grid.primaryKey ? record[grid.primaryKey] : record;
547+
const expanded = states.get(rowID);
548+
549+
if (expanded !== undefined) {
550+
return expanded;
551+
} else {
552+
return grid.getDefaultExpandState(record);
553+
}
554+
}
555+
556+
public set_row_expansion_state(rowID: any, expanded: boolean, event?: Event) {
557+
const grid = this.grid;
558+
const expandedStates = grid.expansionStates;
559+
560+
if (!this.allow_expansion_state_change(rowID, expanded)) {
561+
return;
562+
}
563+
564+
const args: IRowToggleEventArgs = {
565+
rowID: rowID,
566+
expanded: expanded,
567+
event: event,
568+
cancel: false
569+
};
570+
571+
grid.onRowToggle.emit(args);
572+
573+
if (args.cancel) {
574+
return;
575+
}
576+
expandedStates.set(rowID, expanded);
577+
grid.expansionStates = expandedStates;
578+
if (grid.rowEditable) {
579+
grid.endEdit(true);
580+
}
581+
}
582+
583+
public get_rec_by_id(rowID) {
584+
return this.grid.primaryKey ? this.getRowData(rowID) : rowID;
585+
}
586+
587+
public allow_expansion_state_change(rowID, expanded) {
588+
return this.grid.expansionStates.get(rowID) !== expanded;
589+
}
590+
541591
}

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -856,24 +856,14 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
856856
}
857857

858858
protected handleAlt(key: string, event: KeyboardEvent) {
859-
if (this.row.nativeElement.tagName.toLowerCase() === 'igx-tree-grid-row' && this.isToggleKey(key)) {
859+
if (this.isToggleKey(key)) {
860860
const collapse = (this.row as any).expanded && ROW_COLLAPSE_KEYS.has(key);
861861
const expand = !(this.row as any).expanded && ROW_EXPAND_KEYS.has(key);
862-
if (collapse) {
863-
(this.gridAPI as any).trigger_row_expansion_toggle(this.row.treeRow, !this.row.expanded, event, this.visibleColumnIndex);
864-
} else if (expand) {
865-
(this.gridAPI as any).trigger_row_expansion_toggle(this.row.treeRow, !this.row.expanded, event, this.visibleColumnIndex);
866-
}
867-
} else if ((this.grid as IgxGridComponent).hasDetails && this.isToggleKey(key)) {
868-
const collapse = (this.row as any).expanded && ROW_COLLAPSE_KEYS.has(key);
869-
const expand = !(this.row as any).expanded && ROW_EXPAND_KEYS.has(key);
870-
const expandedStates = this.grid.expansionStates;
871862
if (expand) {
872-
expandedStates.set(this.row.rowID, true);
863+
this.gridAPI.set_row_expansion_state(this.row.rowID, true, event);
873864
} else if (collapse) {
874-
expandedStates.set(this.row.rowID, false);
865+
this.gridAPI.set_row_expansion_state(this.row.rowID, false, event);
875866
}
876-
this.grid.expansionStates = expandedStates;
877867
this.grid.notifyChanges();
878868
}
879869
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,10 @@ export interface IRowDragStartEventArgs extends CancelableEventArgs, IBaseEventA
111111
dragDirective: IgxDragDirective;
112112
dragData: IgxRowDirective<IgxGridBaseDirective & IGridDataBindable>;
113113
}
114+
115+
export interface IRowToggleEventArgs extends IBaseEventArgs {
116+
rowID: any;
117+
expanded: boolean;
118+
event?: Event;
119+
cancel: boolean;
120+
}

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ import {
121121
IGridClipboardEvent,
122122
IGridToolbarExportEventArgs,
123123
ISearchInfo,
124-
ICellPosition
124+
ICellPosition,
125+
IRowToggleEventArgs
125126
} from './common/events';
126127
import { IgxAdvancedFilteringDialogComponent } from './filtering/advanced-filtering/advanced-filtering-dialog.component';
127128
import { GridType } from './common/grid.interface';
@@ -1670,6 +1671,34 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
16701671
@Output()
16711672
onGridCopy = new EventEmitter<IGridClipboardEvent>();
16721673

1674+
/**
1675+
*@hidden
1676+
*/
1677+
@Output()
1678+
public expansionStatesChange = new EventEmitter<Map<any, boolean>>();
1679+
1680+
/**
1681+
* Emitted when the expanded state of a row gets changed.
1682+
* ```typescript
1683+
* rowToggle(event: IRowToggleEventArgs){
1684+
* // the id of the row
1685+
* const rowID = event.rowID;
1686+
* // the new expansion state
1687+
* const newExpandedState = event.expanded;
1688+
* // the original event that triggered onRowToggle
1689+
* const originalEvent = event.event;
1690+
* // whether the event should be cancelled
1691+
* event.cancel = true;
1692+
* }
1693+
* ```
1694+
* ```html
1695+
* <igx-grid [data]="employeeData" (onRowToggle)="rowToggle($event)" [autoGenerate]="true"></igx-grid>
1696+
* ```
1697+
* @memberof IgxGridBaseDirective
1698+
*/
1699+
@Output()
1700+
public onRowToggle = new EventEmitter<IRowToggleEventArgs>();
1701+
16731702
/**
16741703
* @hidden
16751704
*/
@@ -2825,7 +2854,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
28252854
private _horizontalForOfs: Array<IgxGridForOfDirective<any>> = [];
28262855
private _multiRowLayoutRowSize = 1;
28272856
protected _loadingId;
2828-
2857+
protected _expansionStates: Map<any, boolean> = new Map<any, boolean>();
2858+
protected _defaultExpandState = false;
28292859
// Caches
28302860
private _totalWidth = NaN;
28312861
private _pinnedVisible = [];
@@ -3332,6 +3362,112 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
33323362
this.onColumnVisibilityChanged.emit(args);
33333363
}
33343364

3365+
/**
3366+
* Returns a list of key-value pairs [row ID, expansion state]. Includes only states that differ from the default one.
3367+
* ```typescript
3368+
* const expansionStates = this.grid.expansionStates;
3369+
* ```
3370+
* @memberof IgxGridComponent
3371+
*/
3372+
@Input()
3373+
public get expansionStates() {
3374+
return this._expansionStates;
3375+
}
3376+
3377+
/**
3378+
* Sets a list of key-value pairs [row ID, expansion state].
3379+
* ```typescript
3380+
* const states = new Map<any, boolean>();
3381+
* states.set(1, true);
3382+
* this.grid.expansionStates = states;
3383+
* ```
3384+
*
3385+
* Two-way data binding.
3386+
* ```html
3387+
* <igx-grid #grid [data]="data" [(expansionStates)]="model.expansionStates">
3388+
* <ng-template igxGridDetail let-dataItem>
3389+
* <div *ngIf="dataItem.Category">
3390+
* <header>{{dataItem.Category?.CategoryName}}</header>
3391+
* <span>{{dataItem.Category?.Description}}</span>
3392+
* </div>
3393+
* </ng-template>
3394+
* </igx-grid>
3395+
* ```
3396+
* @memberof IgxGridBaseDirective
3397+
*/
3398+
public set expansionStates(value) {
3399+
this._expansionStates = new Map<any, boolean>(value);
3400+
this.expansionStatesChange.emit(this._expansionStates);
3401+
if (this.gridAPI.grid) {
3402+
this.cdr.detectChanges();
3403+
this._focusActiveCell();
3404+
}
3405+
}
3406+
3407+
/**
3408+
* Expands all rows.
3409+
* ```typescript
3410+
* this.grid.expandAll();
3411+
* ```
3412+
* @memberof IgxGridBaseDirective
3413+
*/
3414+
public expandAll() {
3415+
this._defaultExpandState = true;
3416+
this.expansionStates = new Map<any, boolean>();
3417+
}
3418+
3419+
/**
3420+
* Collapses all rows.
3421+
* ```typescript
3422+
* this.grid.collapseAll();
3423+
* ```
3424+
* @memberof IgxGridBaseDirective
3425+
*/
3426+
public collapseAll() {
3427+
this._defaultExpandState = false;
3428+
this.expansionStates = new Map<any, boolean>();
3429+
}
3430+
3431+
/**
3432+
* Expands the row by its id. ID is either the primaryKey value or the data record instance.
3433+
* ```typescript
3434+
* this.grid.expandRow(rowID);
3435+
* ```
3436+
* @memberof IgxGridBaseDirective
3437+
*/
3438+
public expandRow(rowID: any) {
3439+
this.gridAPI.set_row_expansion_state(rowID, true);
3440+
}
3441+
3442+
/**
3443+
* Collapses the row by its id. ID is either the primaryKey value or the data record instance.
3444+
* ```typescript
3445+
* this.grid.collapseRow(rowID);
3446+
* ```
3447+
* @memberof IgxGridBaseDirective
3448+
*/
3449+
public collapseRow(rowID: any) {
3450+
this.gridAPI.set_row_expansion_state(rowID, false);
3451+
}
3452+
3453+
3454+
/**
3455+
* Toggles the row by its id. ID is either the primaryKey value or the data record instance.
3456+
* ```typescript
3457+
* this.grid.toggleRow(rowID);
3458+
* ```
3459+
* @memberof IgxGridBaseDirective
3460+
*/
3461+
public toggleRow(rowID: any) {
3462+
const rec = this.gridAPI.get_rec_by_id(rowID);
3463+
const state = this.gridAPI.get_row_expansion_state(rec);
3464+
this.gridAPI.set_row_expansion_state(rowID, !state);
3465+
}
3466+
3467+
public getDefaultExpandState(rec: any) {
3468+
return this._defaultExpandState;
3469+
}
3470+
33353471
/**
33363472
* Returns the native element of the `IgxGridComponent`.
33373473
* ```typescript

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,8 @@ export class IgxGridExpandableCellComponent extends IgxGridCellComponent impleme
5959
*/
6060
public toggle(event: Event) {
6161
event.stopPropagation();
62-
const expandedStates = this.grid.expansionStates;
63-
expandedStates.set(this.row.rowID, !this.row.expanded);
64-
this.grid.expansionStates = expandedStates;
65-
66-
if (this.grid.rowEditable) {
67-
this.grid.endEdit(true);
68-
}
62+
const expansionState = this.gridAPI.get_row_expansion_state(this.row.rowData);
63+
this.gridAPI.set_row_expansion_state(this.row.rowID, !expansionState, event);
6964
}
7065

7166
/**

projects/igniteui-angular/src/lib/grids/grid/grid-mrl-keyboard-nav.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ describe('IgxGrid Multi Row Layout - Keyboard navigation #grid', () => {
16371637
]
16381638
}];
16391639
fix.detectChanges();
1640+
await wait(DEBOUNCETIME * 2);
16401641

16411642
let firstCell;
16421643
let secondCell;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export class IgxGridRowComponent extends IgxRowDirective<IgxGridComponent> {
5555
}
5656

5757
get expanded() {
58-
const pk = this.grid.primaryKey;
59-
const rowID = pk ? this.rowData[pk] : this.rowData;
60-
return this.grid.expansionStates.get(rowID);
58+
return this.gridAPI.get_row_expansion_state(this.rowData);
6159
}
6260
}

0 commit comments

Comments
 (0)