Skip to content

Commit de7dae9

Browse files
committed
use document fragment to increase performance for large tables
1 parent 23ea67d commit de7dae9

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

coffee/sortable.coffee

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,19 @@ sortable =
9191
rowArray.push [value, row, position]
9292

9393
rowArray.sort compare
94-
tBody.appendChild row[1] for row in rowArray
94+
# use document fragment for performance
95+
# when sorting large tables (avoid recalculating styles)
96+
fragment = document.createDocumentFragment()
97+
fragment.appendChild row[1] for row in rowArray
98+
tBody.appendChild fragment
9599
else
96100
rowArray.push item for item in tBody.rows
97101
rowArray.reverse()
98-
tBody.appendChild row for row in rowArray
102+
# use document fragment for performance
103+
# when sorting large tables (avoid recalculating styles)
104+
fragment = document.createDocumentFragment()
105+
fragment.appendChild row for row in rowArray
106+
tBody.appendChild fragment
99107

100108
if typeof window['CustomEvent'] is 'function'
101109
table.dispatchEvent?(new CustomEvent 'Sortable.sorted', { bubbles: true })

js/sortable.js

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/sortable.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)