diff --git a/shared/editor/commands/table.ts b/shared/editor/commands/table.ts index 31de593a3..c1a603584 100644 --- a/shared/editor/commands/table.ts +++ b/shared/editor/commands/table.ts @@ -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);