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(igxGrid): Use SelectedRowsChange for two-way bind for Blazor. #14745

Merged
merged 3 commits into from
Oct 22, 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
10 changes: 9 additions & 1 deletion projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,11 @@ export abstract class IgxGridBaseDirective implements GridType,
@Output()
public expansionStatesChange = new EventEmitter<Map<any, boolean>>();

/* blazorInclude */
/** @hidden @internal */
@Output()
public selectedRowsChange = new EventEmitter<any[]>();

/**
* Emitted when the expanded state of a row gets changed.
*
Expand Down Expand Up @@ -2458,7 +2463,7 @@ export abstract class IgxGridBaseDirective implements GridType,

/* blazorByValueArray */
/* blazorAlwaysWriteback */
/* @tsTwoWayProperty (true, "RowSelectionChanging", "Detail.NewSelection", false) */
/* @tsTwoWayProperty (true, "SelectedRowsChange", "Detail", false) */
/* blazorPrimitiveValue */
/**
* Gets/Sets the current selection state.
Expand Down Expand Up @@ -3412,6 +3417,9 @@ export abstract class IgxGridBaseDirective implements GridType,
this._transactions = this.transactionFactory.create(TRANSACTION_TYPE.None);
this._transactions.cloneStrategy = this.dataCloneStrategy;
this.cdr.detach();
this.selectionService.selectedRowsChange.pipe(takeUntil(this.destroy$)).subscribe((args: any[]) => {
this.selectedRowsChange.emit(args);
});
IgcTrialWatermark.register();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class IgxGridSelectionService {
/**
* @hidden @internal
*/
public selectedRowsChange = new Subject<void>();
public selectedRowsChange = new Subject<any[]>();

/**
* Toggled when a pointerdown event is triggered inside the grid body (cells).
Expand Down Expand Up @@ -561,14 +561,14 @@ export class IgxGridSelectionService {
}
rowIDs.forEach(rowID => this.rowSelection.add(rowID));
this.clearHeaderCBState();
this.selectedRowsChange.next();
this.selectedRowsChange.next(rowIDs);
}

/** Deselect specified rows. No event is emitted. */
public deselectRowsWithNoEvent(rowIDs: any[]): void {
this.clearHeaderCBState();
rowIDs.forEach(rowID => this.rowSelection.delete(rowID));
this.selectedRowsChange.next();
this.selectedRowsChange.next(this.getSelectedRows());
}

public isRowSelected(rowID): boolean {
Expand Down Expand Up @@ -689,7 +689,7 @@ export class IgxGridSelectionService {
this.rowSelection.clear();
this.indeterminateRows.clear();
this.clearHeaderCBState();
this.selectedRowsChange.next();
this.selectedRowsChange.next([]);
}

/** Returns all data in the grid, with applied filtering and sorting and without deleted rows. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class IgxTreeGridSelectionService extends IgxGridSelectionService {
this.indeterminateRows = new Set(this.rowsToBeIndeterminate);
// TODO: emit selectionChangeD event, calculate its args through the handleAddedAndRemovedArgs method
this.clearHeaderCBState();
this.selectedRowsChange.next();
this.selectedRowsChange.next(this.getSelectedRows());
return;
}
const newParents = new Set<any>();
Expand Down Expand Up @@ -89,7 +89,7 @@ export class IgxTreeGridSelectionService extends IgxGridSelectionService {
this.rowSelection = new Set(this.rowsToBeSelected);
this.indeterminateRows = new Set(this.rowsToBeIndeterminate);
this.clearHeaderCBState();
this.selectedRowsChange.next();
this.selectedRowsChange.next(this.getSelectedRows());
}

private cascadeDeselectRowsWithNoEvent(rowIDs: any[]): void {
Expand All @@ -99,7 +99,7 @@ export class IgxTreeGridSelectionService extends IgxGridSelectionService {
this.rowSelection = new Set(this.rowsToBeSelected);
this.indeterminateRows = new Set(this.rowsToBeIndeterminate);
this.clearHeaderCBState();
this.selectedRowsChange.next();
this.selectedRowsChange.next(this.getSelectedRows());
}

public get selectionService(): IgxGridSelectionService {
Expand Down Expand Up @@ -134,7 +134,7 @@ export class IgxTreeGridSelectionService extends IgxGridSelectionService {
this.rowSelection = new Set(this.rowsToBeSelected);
this.indeterminateRows = new Set(this.rowsToBeIndeterminate);
this.clearHeaderCBState();
this.selectedRowsChange.next();
this.selectedRowsChange.next(this.getSelectedRows());
} else {
// select the rows within the modified args.newSelection with no event
this.cascadeSelectRowsWithNoEvent(newSelectionIDs, true);
Expand Down
Loading