Skip to content

Commit

Permalink
Merge pull request #15177 from primefaces/revert-15159-issue-15158
Browse files Browse the repository at this point in the history
Revert "Fixed #15158 - TreeTable | Update selection logic and fix partial sel…"
  • Loading branch information
cetincakiroglu authored Mar 27, 2024
2 parents 3414de1 + 9527493 commit 4bfea95
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions src/app/components/treetable/treetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1813,35 +1813,19 @@ export class TreeTable implements AfterContentInit, OnInit, OnDestroy, Blockable
}
}

isSelected(node: TreeTableNode): boolean {
isSelected(node: TreeTableNode) {
if (node && this.selection) {
if (this.dataKey) {
return this.selectionKeys[ObjectUtils.resolveFieldData(node.data, this.dataKey)] !== undefined;
} else {
if (Array.isArray(this.selection)) {
return this.allChildrenOrNodeSelected(node);
} else {
return this.equals(node, this.selection);
}
if (Array.isArray(this.selection)) return this.findIndexInSelection(node) > -1;
else return this.equals(node, this.selection);
}
}

return false;
}

allChildrenOrNodeSelected(node: TreeTableNode): boolean {
if (this.findIndexInSelection(node) == -1 && node.parent) {
if (this.findIndexInSelection(node.parent) !== -1) {
return true;
}
}
if (!node.children) {
return this.selection.some((selectedItem) => this.equals(node, selectedItem));
} else {
return node.children.every((child) => this.isSelected(child)) || this.selection.some((selectedItem) => this.equals(node, selectedItem));
}
}

findIndexInSelection(node: any) {
let index: number = -1;
if (this.selection && this.selection.length) {
Expand Down Expand Up @@ -2949,13 +2933,13 @@ export class TTContextMenuRow {
<div class="p-hidden-accessible">
<input type="checkbox" [checked]="checked" (focus)="onFocus()" (blur)="onBlur()" tabindex="-1" />
</div>
<div #box [ngClass]="{ 'p-checkbox-box': true, 'p-highlight': checked, 'p-focus': focused, 'p-indeterminate': isPartialSelected(), 'p-disabled': disabled }" role="checkbox" [attr.aria-checked]="checked">
<div #box [ngClass]="{ 'p-checkbox-box': true, 'p-highlight': checked, 'p-focus': focused, 'p-indeterminate': rowNode.node.partialSelected, 'p-disabled': disabled }" role="checkbox" [attr.aria-checked]="checked">
<ng-container *ngIf="!tt.checkboxIconTemplate">
<CheckIcon [styleClass]="'p-checkbox-icon'" *ngIf="checked" />
<MinusIcon [styleClass]="'p-checkbox-icon'" *ngIf="isPartialSelected()" />
<MinusIcon [styleClass]="'p-checkbox-icon'" *ngIf="rowNode.node.partialSelected" />
</ng-container>
<span *ngIf="tt.checkboxIconTemplate">
<ng-template *ngTemplateOutlet="tt.checkboxIconTemplate; context: { $implicit: checked, partialSelected: isPartialSelected() }"></ng-template>
<ng-template *ngTemplateOutlet="tt.checkboxIconTemplate; context: { $implicit: checked, partialSelected: rowNode.node.partialSelected }"></ng-template>
</span>
</div>
</div>
Expand Down Expand Up @@ -2988,16 +2972,6 @@ export class TTCheckbox {
this.checked = this.tt.isSelected(this.rowNode.node);
}

isPartialSelected() {
const node = this.rowNode.node;
if (node['partialSelected']) {
return !this.checked && node['partialSelected'];
}
if (node['partialSelected'] == undefined && node.children && node.children.length > 0) {
return !this.checked && node.children.some((child) => this.tt.isSelected(child));
}
}

onClick(event: Event) {
if (!this.disabled) {
this.tt.toggleNodeWithCheckbox({
Expand Down

0 comments on commit 4bfea95

Please sign in to comment.