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

Fixed #16618 - Table | Bug on table checkboxes #16619

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
29 changes: 27 additions & 2 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ export class TableService {
private valueSource = new Subject<any>();
private totalRecordsSource = new Subject<any>();
private columnsSource = new Subject();
private isHeaderCheckboxSelection = new Subject<any>();

sortSource$ = this.sortSource.asObservable();
isHeaderCheckboxSelection$ = this.isHeaderCheckboxSelection.asObservable();
selectionSource$ = this.selectionSource.asObservable();
contextMenuSource$ = this.contextMenuSource.asObservable();
valueSource$ = this.valueSource.asObservable();
Expand Down Expand Up @@ -118,6 +120,10 @@ export class TableService {
onColumnsChange(columns: any[]) {
this.columnsSource.next(columns);
}

onHeaderCheckboxSelection(value) {
this.isHeaderCheckboxSelection.next(value);
}
}
/**
* Table displays data in tabular format.
Expand Down Expand Up @@ -4790,15 +4796,26 @@ export class TableCheckbox {

subscription: Subscription;

tableHeaderCheckboxSubscription: Subscription;

isTableHeaderCheckboxSelection: boolean = false;

constructor(
public dt: Table,
public tableService: TableService,
public cd: ChangeDetectorRef
) {
this.subscription = this.dt.tableService.selectionSource$.subscribe(() => {
this.checked = this.dt.isSelected(this.value) && !this.disabled;
setTimeout(() => {
this.checked = this.isTableHeaderCheckboxSelection ? this.dt.isSelected(this.value) && !this.disabled : this.dt.isSelected(this.value);
this.cd.markForCheck();
});

this.ariaLabel = this.ariaLabel || this.dt.config.translation.aria ? (this.checked ? this.dt.config.translation.aria.selectRow : this.dt.config.translation.aria.unselectRow) : undefined;
this.cd.markForCheck();
});

this.tableHeaderCheckboxSubscription = this.dt.tableService.isHeaderCheckboxSelection$.subscribe((val) => {
this.isTableHeaderCheckboxSelection = val;
});
}

Expand All @@ -4815,6 +4832,7 @@ export class TableCheckbox {
},
this.value
);
this.tableService.onHeaderCheckboxSelection(false);
}
DomHandler.clearSelection();
}
Expand All @@ -4831,6 +4849,10 @@ export class TableCheckbox {
if (this.subscription) {
this.subscription.unsubscribe();
}

if (this.tableHeaderCheckboxSubscription) {
this.tableHeaderCheckboxSubscription.unsubscribe();
}
}
}

Expand Down Expand Up @@ -4874,6 +4896,8 @@ export class TableHeaderCheckbox {

valueChangeSubscription: Subscription;

tableHeaderCheckboxSubscription: Subscription;

constructor(
public dt: Table,
public tableService: TableService,
Expand All @@ -4896,6 +4920,7 @@ export class TableHeaderCheckbox {
onClick(event: Event) {
if (!this.disabled) {
if (this.dt.value && this.dt.value.length > 0) {
this.tableService.onHeaderCheckboxSelection(true);
this.dt.toggleRowsWithCheckbox(event, !this.checked);
}
}
Expand Down
Loading