Skip to content

Commit 190f29d

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Update active indexes on events. Cache result to limit pipe trigger.
1 parent d025473 commit 190f29d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,6 +3246,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32463246
private _filteredSortedData = null;
32473247
private _filteredData = null;
32483248
private _mergedDataInView = null;
3249+
private _activeRowIndexes = null;
32493250

32503251
private _customDragIndicatorIconTemplate: TemplateRef<IgxGridEmptyTemplateContext>;
32513252
private _excelStyleHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext>;
@@ -3907,6 +3908,14 @@ export abstract class IgxGridBaseDirective implements GridType,
39073908
this.autoSizeColumnsInView();
39083909
this._firstAutoResize = false;
39093910
});
3911+
3912+
this.activeNodeChange.pipe(filter(() => !this._init), destructor).subscribe(() => {
3913+
this._activeRowIndexes = null;
3914+
});
3915+
3916+
this.selectionService.selectedRangeChange.pipe(filter(() => !this._init), destructor).subscribe(() => {
3917+
this._activeRowIndexes = null;
3918+
});
39103919
}
39113920

39123921
/**
@@ -4055,9 +4064,14 @@ export abstract class IgxGridBaseDirective implements GridType,
40554064

40564065

40574066
protected get activeRowIndexes(): number[] {
4058-
const activeRow = this.navigation.activeNode?.row;
4059-
const selectedCellIndexes = (this.selectionService.selection?.keys() as any)?.toArray();
4060-
return [activeRow, ...selectedCellIndexes];
4067+
if (this._activeRowIndexes) {
4068+
return this._activeRowIndexes;
4069+
} else {
4070+
const activeRow = this.navigation.activeNode?.row;
4071+
const selectedCellIndexes = (this.selectionService.selection?.keys() as any)?.toArray();
4072+
this._activeRowIndexes = [activeRow, ...selectedCellIndexes];
4073+
return this._activeRowIndexes;
4074+
}
40614075
}
40624076

40634077
protected get hasCellsToMerge() {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export class IgxGridSelectionService {
3535
*/
3636
public selectedRowsChange = new Subject<any[]>();
3737

38+
/**
39+
* @hidden @internal
40+
*/
41+
public selectedRangeChange = new Subject<Map<number, Set<number>>>();
42+
3843
/**
3944
* Toggled when a pointerdown event is triggered inside the grid body (cells).
4045
* When `false` the drag select behavior is disabled.
@@ -355,6 +360,8 @@ export class IgxGridSelectionService {
355360
}
356361
}
357362
}
363+
364+
this.selectedRangeChange.next(collection);
358365
}
359366

360367
public dragSelect(node: ISelectionNode, state: SelectionState): void {
@@ -637,7 +644,7 @@ export class IgxGridSelectionService {
637644
if (this.areEqualCollections(currSelection, newSelection)) {
638645
return;
639646
}
640-
647+
641648
const args: IRowSelectionEventArgs = {
642649
owner: this.grid,
643650
oldSelection: currSelection,

0 commit comments

Comments
 (0)