Typically, when I sort a table in the DOM, I create a data array that mirrors the table elements, capturing the information that's meaningful to me (including any attributes that are relevant) in JS objects. At this point, after determining the proper sort, I have two choices:
- Rewrite the data in the table (using innerHTML, textContent, etc.), iterating over all the table elements.
- Reorder the table row element (i.e. HTML nodes) to reflect the proper order in the sorted array.
Which method is less costly (i.e. faster)? I assume it's the latter, but I'm not sure. Can you explain why a particular method is faster?