Skip to content

Commit 107ea90

Browse files
MayaKirovaMKirovadkamburovChronosSF
authored
fix(igxPivot): Get selection from service so that it is consistent be… (#12064)
* fix(igxPivot): Get selection from service so that it is consistent between grids. * chore(*): Add test. Co-authored-by: MKirova <MKirova@DEV-MKIROVA> Co-authored-by: Deyan Kamburov <[email protected]> Co-authored-by: Stamen Stoychev <[email protected]>
1 parent 42c3c39 commit 107ea90

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

projects/igniteui-angular/src/lib/grids/state.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class IgxGridStateDirective {
292292
},
293293
rowSelection: {
294294
getFeatureState: (context: IgxGridStateDirective): IGridState => {
295-
const selection = context.currGrid.selectedRows;
295+
const selection = context.currGrid.selectionService.getSelectedRows();
296296
return { rowSelection: selection };
297297
},
298298
restoreFeatureState: (context: IgxGridStateDirective, state: any[]): void => {

projects/igniteui-angular/src/lib/grids/state.pivotgrid.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ describe('IgxPivotGridState #pivotGrid :', () => {
230230
expect(rowDimensionHeaders).toEqual(expectedHeaders);
231231
});
232232

233+
it('should successfully restore the selected rows.', () => {
234+
pivotGrid.rowSelection = 'single';
235+
const state = fixture.componentInstance.state;
236+
expect(state).toBeDefined('IgxGridState directive is initialized');
237+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-row-dimension-content');
238+
const header = headerRow.querySelector('igx-pivot-row-dimension-header');
239+
header.click();
240+
fixture.detectChanges();
241+
expect(pivotGrid.selectedRows.length).toBe(2);
242+
const jsonString = state.getState(true);
243+
// clear
244+
pivotGrid. selectionService.rowSelection.clear();
245+
expect(pivotGrid.selectedRows.length).toBe(0);
246+
// set old state
247+
state.setState(jsonString);
248+
fixture.detectChanges();
249+
expect(pivotGrid.selectedRows.length).toBe(2);
250+
});
251+
233252
it('should allow setting back custom functions on init.', async() => {
234253
const state = fixture.componentInstance.state;
235254
const customFunc = () => 'All';

0 commit comments

Comments
 (0)