From f2c0c7d077ec81eb53c2422548ad3b09de4d50fa Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Wed, 21 Aug 2024 13:44:04 +0200 Subject: [PATCH] fix sorting of negative numeric values, fixes #392 --- docs/demos/28-sort-order-attribute/index.html | 60 +++++++++++++++++++ docs/demos/index.html | 1 + src/columns.ts | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 docs/demos/28-sort-order-attribute/index.html diff --git a/docs/demos/28-sort-order-attribute/index.html b/docs/demos/28-sort-order-attribute/index.html new file mode 100644 index 0000000..d7c7ca8 --- /dev/null +++ b/docs/demos/28-sort-order-attribute/index.html @@ -0,0 +1,60 @@ + + + + + + + Numeric sort - simple-datatables + + + + + + +
+

+ simple-datatables +

+ Documentation + Demos +
+ +

Data-order attributes take precedence over cell values.

+

Try sorting the two table columns.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameVariation
A2000.9%
B100.3%
C20%
D-7%
E-9%
+ + + diff --git a/docs/demos/index.html b/docs/demos/index.html index 17f35c5..2f21471 100644 --- a/docs/demos/index.html +++ b/docs/demos/index.html @@ -44,6 +44,7 @@

Demos

Cell attributes Numeric sort Load JSON + Sort order attribute diff --git a/src/columns.ts b/src/columns.ts index d7bba44..2eb9bd5 100644 --- a/src/columns.ts +++ b/src/columns.ts @@ -318,7 +318,7 @@ export class Columns { order1 = order2 order2 = temp } - if (collator) { + if (collator && (typeof order1 !== "number") && (typeof order2 !== "number")) { return collator.compare(String(order1), String(order2)) } if (order1 < order2) {