fix: no-op table sort should not modify document
This commit is contained in:
@@ -119,6 +119,9 @@ export function sortTable({
|
||||
// remove the header row
|
||||
const header = table.shift();
|
||||
|
||||
// column data before sort
|
||||
const columnData = table.map((row) => row[index]?.textContent ?? "");
|
||||
|
||||
// sort table data based on column at index
|
||||
table.sort((a, b) => {
|
||||
if (compareAsText) {
|
||||
@@ -137,6 +140,13 @@ export function sortTable({
|
||||
table.reverse();
|
||||
}
|
||||
|
||||
// check if column data changed, if not then do not replace table
|
||||
if (
|
||||
columnData.join() === table.map((row) => row[index]?.textContent).join()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// add the header row back
|
||||
if (header) {
|
||||
table.unshift(header);
|
||||
|
||||
Reference in New Issue
Block a user