From a9cd1a6d02921fdd92e284a7888a10cecc2edef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sun, 1 May 2022 18:46:12 -0700 Subject: [PATCH 1/2] dispatch the value on sort events, with details allowing to read the sort+reverse method closes https://github.com/observablehq/inputs/issues/115 --- src/table.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/table.js b/src/table.js index bd2df74..451d73a 100644 --- a/src/table.js +++ b/src/table.js @@ -238,6 +238,7 @@ function initialize( while (tbody.firstChild) tbody.firstChild.remove(); appendRows(0, n = minlengthof(rows * 2)); anchor = head = null; + root.dispatchEvent(new CustomEvent('input', {bubbles: true, detail: {sort: column, reverse: currentReverse}})); reinput(); } From 4f20620c59891726f389cbc16ce2001b74d6da75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sun, 1 May 2022 18:44:58 -0700 Subject: [PATCH 2/2] if there is an active sort, return the selection in the order of the index --- src/table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/table.js b/src/table.js index 451d73a..6a553f6 100644 --- a/src/table.js +++ b/src/table.js @@ -292,7 +292,7 @@ function initialize( if (value === undefined) { materialize(); if (multiple) { - value = Array.from(required && selected.size === 0 ? index : selected, i => array[i]); + value = Array.from(required && selected.size === 0 ? index : sort ? index.filter(i => selected.has(i)) : selected, i => array[i]); value.columns = columns; } else if (selected.size) { const [i] = selected;