Skip to content

Commit fbb7e18

Browse files
Merge pull request #13824 from IgniteUI/bpachilova/fix-13762-17.0.x
fix(tree-grid): get newSelection from all data - 17.0.x
2 parents 86cc7c4 + e85c6bd commit fbb7e18

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class IgxTreeGridSelectionService extends IgxGridSelectionService {
118118
};
119119

120120
this.calculateRowsNewSelectionState(args, !!this.grid.primaryKey);
121-
args.newSelection = Array.from(this.allData.filter(r => this.rowsToBeSelected.has(this.grid.primaryKey ? r[this.grid.primaryKey] : r)));
121+
args.newSelection = Array.from(this.grid.gridAPI.get_all_data().filter(r => this.rowsToBeSelected.has(this.grid.primaryKey ? r[this.grid.primaryKey] : r)));
122122

123123
// retrieve rows/parents/children which has been added/removed from the selection
124124
this.handleAddedAndRemovedArgs(args);

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-selection.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,47 @@ describe('IgxTreeGrid - Selection #tGrid', () => {
14881488
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 3, true, true);
14891489
});
14901490

1491+
it(`Parent with two or more children. Select parent. Filter out one of the children. Deselect all the others -> children
1492+
and parent checkbox state becomes deselected. Filter the other child back in. This child should remain selected.
1493+
Parent checkbox state should be indeterminate.`, fakeAsync(() => {
1494+
treeGrid.selectRows([147], true);
1495+
fix.detectChanges();
1496+
1497+
expect(getVisibleSelectedRows(fix).length).toBe(7);
1498+
1499+
const expressionTree = new FilteringExpressionsTree(FilteringLogic.And, 'ID');
1500+
expressionTree.filteringOperands = [
1501+
{
1502+
condition: IgxNumberFilteringOperand.instance().condition('doesNotEqual'),
1503+
fieldName: 'ID',
1504+
searchVal: 957
1505+
},
1506+
];
1507+
treeGrid.filter('ID', null, expressionTree);
1508+
1509+
fix.detectChanges();
1510+
tick(100);
1511+
1512+
expect(getVisibleSelectedRows(fix).length).toBe(6);
1513+
1514+
treeGrid.deselectRows([475, 317]);
1515+
fix.detectChanges();
1516+
1517+
expect(getVisibleSelectedRows(fix).length).toBe(0);
1518+
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 0, false, false);
1519+
1520+
treeGrid.clearFilter();
1521+
1522+
tick(1000);
1523+
fix.detectChanges();
1524+
1525+
expect(getVisibleSelectedRows(fix).length).toBe(1);
1526+
expect(treeGrid.selectionService.indeterminateRows.size).toBe(1);
1527+
TreeGridFunctions.verifyHeaderCheckboxSelection(fix, null);
1528+
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 2, true, true);
1529+
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 0, null, null);
1530+
}));
1531+
14911532
it(`Parent in indeterminate state. Filter out its children -> parent not selected. Select parent and add new child.
14921533
Parent -> not selected. Revert filtering so that previous records are back in the view and parent should become in
14931534
indeterminate state because one of it children is selected`, fakeAsync(() => {

0 commit comments

Comments
 (0)