Skip to content

Commit

Permalink
fix: checkbox checked when all selectable items selected (#598)
Browse files Browse the repository at this point in the history
Co-authored-by: SchettlerKoehler <[email protected]>
  • Loading branch information
markuczy and SchettlerKoehler authored Nov 13, 2024
1 parent ec220dc commit cef84ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
scrollHeight="flex"
[style]="tableStyle"
paginatorDropdownAppendTo="body"
[rowSelectable]="rowSelectable"
tableStyleClass="h-full"
>
<ng-template pTemplate="header">
Expand Down Expand Up @@ -233,7 +234,7 @@
<tr>
<td *ngIf="selectionChangedObserved">
<p-checkbox
*ngIf="(!!selectionEnabledField && !fieldIsTruthy(rowObject, selectionEnabledField)) && isSelected(rowObject); else defaultCheckbox"
*ngIf="isRowSelectionDisabled(rowObject) && isSelected(rowObject); else defaultCheckbox"
[(ngModel)]="checked"
[binary]="true"
[disabled]="true"
Expand All @@ -242,7 +243,7 @@
<ng-template #defaultCheckbox>
<p-tableCheckbox
[value]="rowObject"
[disabled]="!!selectionEnabledField && !fieldIsTruthy(rowObject, selectionEnabledField)"
[disabled]="isRowSelectionDisabled(rowObject)"
[ariaLabel]="'OCX_DATA_TABLE.SELECT_ARIA_LABEL' | translate: { key: rowObject.id}"
></p-tableCheckbox>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
)
)
)
this.rowSelectable = this.rowSelectable.bind(this)
}

ngOnInit(): void {
Expand Down Expand Up @@ -670,6 +671,14 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
)
}

isRowSelectionDisabled(rowObject: Row) {
return !!this.selectionEnabledField && !this.fieldIsTruthy(rowObject, this.selectionEnabledField)
}

rowSelectable(event: any) {
return !this.isRowSelectionDisabled(event.data)
}

onSelectionChange(selection: Row[]) {
let newSelectionIds = selection.map((row) => row.id)
const rows = this._rows$.getValue()
Expand Down

0 comments on commit cef84ce

Please sign in to comment.