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 2024/09/04 11:18:38 UTC

(myfaces-tobago) 01/03: fix(sheet-lazy): tobago-behavior not initialized

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

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

commit 69160619587f09d6f971b7cbdae562e316969c32
Author: Bernd Bohmann <bo...@apache.org>
AuthorDate: Wed Sep 4 11:57:43 2024 +0200

    fix(sheet-lazy): tobago-behavior not initialized
    
    issue: TOBAGO-2349
---
 .../tobago-theme-standard/src/main/ts/tobago-sheet.ts       | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

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 9aa2351f8b..98d6791af3 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
@@ -517,8 +517,17 @@ export class Sheet extends HTMLElement {
             if (newRow.hasAttribute("row-index")) {
               const rowIndex = Number(newRow.getAttribute("row-index"));
               const row = this.tableBody.querySelector(`tr[row-index='${rowIndex}']`);
-              row.insertAdjacentElement("afterend", newRow);
-              row.remove();
+              const previousElement = row.previousElementSibling;
+              // first remove the old element and then add the new element
+              // otherwise eventlisteners cannot be registered
+              if (previousElement == null) {
+                const parentElement = row.parentElement;
+                row.remove();
+                parentElement.insertAdjacentElement("afterbegin", newRow);
+              } else {
+                row.remove();
+                previousElement.insertAdjacentElement("afterend", newRow);
+              }
             } else if (newRow.classList.contains(Css.TOBAGO_COLUMN_PANEL)) {
               const rowIndex = Number(newRow.getAttribute("name"));
               const columnPanel = this.tableBody.querySelector(`tr[name='${rowIndex}'].${Css.TOBAGO_COLUMN_PANEL}`);