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

Tree grid selection #3334

Merged
merged 5 commits into from
Dec 7, 2018
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
2 changes: 1 addition & 1 deletion projects/igniteui-angular/src/lib/core/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class IgxSelectionAPIService {
* @returns If all items are selected.
*/
public are_all_selected(componentID: string, dataCount: number): boolean {
return this.size(componentID) === dataCount;
return dataCount > 0 && dataCount === this.size(componentID);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,17 @@ export class IgxTreeGridAPIService extends GridBaseAPIService<IgxTreeGridCompone
public should_apply_number_style(column: IgxColumnComponent): boolean {
return column.dataType === DataType.Number && column.visibleIndex !== 0;
}

public get_selected_children(id: string, record: ITreeGridRecord, selectedRowIDs: any[]) {
const grid = this.get(id);
if (!record.children || record.children.length === 0) {
return;
}
for (const child of record.children) {
if (grid.selection.is_item_selected(id, child.rowID)) {
selectedRowIDs.push(child.rowID);
}
this.get_selected_children(id, child, selectedRowIDs);
}
wnvko marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ describe('IgxTreeGrid - Selection', () => {
TreeGridFunctions.verifyHeaderCheckboxSelection(fix, false);
});

it('when all items are selected and then some of the selected rows are deleted, still all the items should be selected', () => {
treeGrid.selectAllRows();
fix.detectChanges();
TreeGridFunctions.verifyHeaderCheckboxSelection(fix, true);

treeGrid.deleteRowById(treeGrid.selectedRows()[0]);
fix.detectChanges();
TreeGridFunctions.verifyHeaderCheckboxSelection(fix, true);

treeGrid.deleteRowById(treeGrid.selectedRows()[0]);
fix.detectChanges();
TreeGridFunctions.verifyHeaderCheckboxSelection(fix, true);

treeGrid.deleteRowById(treeGrid.selectedRows()[0]);
fix.detectChanges();
// When deleting the last selected row, header checkbox will be unchecked.
TreeGridFunctions.verifyHeaderCheckboxSelection(fix, false);
});

it('should be able to select row of any level', () => {
treeGrid.selectRows([treeGrid.getRowByIndex(0).rowID], true);
fix.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
const childData = record.parent ? record.parent.data[this.childDataKey] : this.data;
index = this.primaryKey ? childData.map(c => c[this.primaryKey]).indexOf(rowID) :
childData.indexOf(rowID);

const selectedChildren = [];
this._gridAPI.get_selected_children(this.id, record, selectedChildren);
if (selectedChildren.length > 0) {
this.deselectRows(selectedChildren);
}

if (this.transactions.enabled) {
this.transactions.add({
id: rowID,
Expand Down