Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tree-grid): get newSelection from all data #13822

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class IgxTreeGridSelectionService extends IgxGridSelectionService {
};

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

// retrieve rows/parents/children which has been added/removed from the selection
this.handleAddedAndRemovedArgs(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,47 @@ describe('IgxTreeGrid - Selection #tGrid', () => {
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 3, true, true);
});

it(`Parent with two or more children. Select parent. Filter out one of the children. Deselect all the others -> children
and parent checkbox state becomes deselected. Filter the other child back in. This child should remain selected.
Parent checkbox state should be indeterminate.`, fakeAsync(() => {
treeGrid.selectRows([147], true);
fix.detectChanges();

expect(getVisibleSelectedRows(fix).length).toBe(7);

const expressionTree = new FilteringExpressionsTree(FilteringLogic.And, 'ID');
expressionTree.filteringOperands = [
{
condition: IgxNumberFilteringOperand.instance().condition('doesNotEqual'),
fieldName: 'ID',
searchVal: 957
},
];
treeGrid.filter('ID', null, expressionTree);

fix.detectChanges();
tick(100);

expect(getVisibleSelectedRows(fix).length).toBe(6);

treeGrid.deselectRows([475, 317]);
fix.detectChanges();

expect(getVisibleSelectedRows(fix).length).toBe(0);
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 0, false, false);

treeGrid.clearFilter();

tick(1000);
fix.detectChanges();

expect(getVisibleSelectedRows(fix).length).toBe(1);
expect(treeGrid.selectionService.indeterminateRows.size).toBe(1);
TreeGridFunctions.verifyHeaderCheckboxSelection(fix, null);
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 2, true, true);
TreeGridFunctions.verifyRowByIndexSelectionAndCheckboxState(fix, 0, null, null);
}));

it(`Parent in indeterminate state. Filter out its children -> parent not selected. Select parent and add new child.
Parent -> not selected. Revert filtering so that previous records are back in the view and parent should become in
indeterminate state because one of it children is selected`, fakeAsync(() => {
Expand Down
Loading