Skip to content

Commit

Permalink
Update table-sort.js
Browse files Browse the repository at this point in the history
Make sure each table is processed once by adding the class name "table-processed". This prevents re-processing tables and attaching repeated arrows and click events in scenarios where new tables are dynamically added to a web page/application. Now, only new tables are made sortable.
  • Loading branch information
alijsh committed Dec 21, 2023
1 parent 028a473 commit 24e8471
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}

function makeTableSortable(sortableTable) {
if (sortableTable.classList.contains("table-processed")) {
return;
} else {
sortableTable.classList.add("table-processed");
}
const table = {
bodies: getTableBodies(sortableTable),
theads: sortableTable.querySelectorAll("thead"),
Expand Down

0 comments on commit 24e8471

Please sign in to comment.