You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2023/11/06 09:34:20 UTC

(myfaces-tobago) 01/02: fix(sheet): Selector All Checkbox is not synchronized with selector Checkbox in each row after ajax request

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit ab7a7e15a1c642d99656299e43d448d8a36d7946
Author: Bernd Bohmann <bo...@apache.org>
AuthorDate: Fri Nov 3 11:05:32 2023 +0100

    fix(sheet): Selector All Checkbox is not synchronized with selector Checkbox in each row after ajax request
    
    issue: TOBAGO-2254
    
    (cherry picked from commit a9c98992bc819e10a735ac32b6570c2a75230f8e)
---
 .../src/main/ts/tobago-sheet.ts                    | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
index fac0f9ee70..3d8688b444 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
@@ -196,6 +196,10 @@ export class Sheet extends HTMLElement {
         row.addEventListener("click", this.clickOnRow.bind(this));
       }
     }
+    if (selectionMode === "multi"  && this.getSelectorAllCheckbox()) {
+      const selectedSet = new Set<number>(JSON.parse(this.getHiddenSelected().value));
+      this.calculateSelectorAllChecked(selectedSet);
+    }
 
     for (const checkbox of this.querySelectorAll(
         ".tobago-body td > input.tobago-selected")) {
@@ -265,7 +269,6 @@ export class Sheet extends HTMLElement {
       });
     }
   }
-
   // attribute getter + setter ---------------------------------------------------------- //
 
   get lazyActive(): boolean {
@@ -748,6 +751,30 @@ Type: ${data.type}`);
     return row.querySelector("tr>td>input.tobago-selected");
   }
 
+  private getSelectorAllCheckbox(): HTMLInputElement {
+    return this.querySelector("thead>tr>th>span>input.tobago-selected");
+  }
+
+  private calculateSelectorAllChecked(selectedSet: Set<number>) {
+    const selectorAll = this.getSelectorAllCheckbox();
+    if (selectorAll) {
+      let selected = false;
+      for (const row of this.getRowElements()) {
+        const checkbox: HTMLInputElement = this.getSelectorCheckbox(row);
+        if (checkbox === null || !checkbox.disabled) {
+          const rowIndex = Number(row.getAttribute("row-index"));
+          if (selectedSet.has(rowIndex)) {
+            selected = true;
+          } else {
+            selected = false;
+            break;
+          }
+        }
+      }
+      selectorAll.checked = selected;
+    }
+  }
+
   getRowElements(): NodeListOf<HTMLTableRowElement> {
     return this.getBodyTable().querySelectorAll("tbody>tr");
   }
@@ -774,6 +801,7 @@ Type: ${data.type}`);
         this.selectRow(selectedSet, rowIndex, row, checkbox);
       }
     }
+    this.calculateSelectorAllChecked(selectedSet);
   }
 
   selectAll(selectedSet: Set<number>): void {
@@ -807,6 +835,7 @@ Type: ${data.type}`);
         }
       }
     }
+    this.calculateSelectorAllChecked(selectedSet);
   }
 
   /**