Suggestion to change the logic for sorting numbers
Is your feature request related to a problem? Please describe.
The current implementation uses simple lexicographic order, which results in numbers being sorted incorrectly (for example, 10 before 2).
Describe the solution you'd like
I changed the sorting logic a little and now it works correctly.
Additional context Below are the changes I made to the sort() method:
sort() { const compareRows = (rowA, rowB) => { for (const filter of this.filters) { const cellA = rowA.children[filter.id]; const cellB = rowB.children[filter.id]; if (!cellA || !cellB) { return 0; } const valueA = cellA.textContent ? cellA.textContent.trim() : ""; const valueB = cellB.textContent ? cellB.textContent.trim() : ""; const numA = parseFloat(valueA); const numB = parseFloat(valueB); const isNumA = !isNaN(numA); const isNumB = !isNaN(numB); if (isNumA && isNumB) { return (numA - numB) * filter.getWeight(); } else { if (valueA < valueB) { return -1 * filter.getWeight(); } if (valueA > valueB) { return 1 * filter.getWeight(); } } } return 0; }; if (this.filters.length == 0) { this.currentOrder = this.originalOrder; } else { this.currentOrder = Array.from(this.currentOrder).sort((rowA, rowB) => { return compareRows(rowA, rowB); }); TableSort.log("[obsidian-table-sorting] sort() - Finished sorting rows."); } this.fillTable(); }