From ad1cbce61b53361792cfa868bff4daf438c71da4 Mon Sep 17 00:00:00 2001 From: Andrei Alexandru Date: Mon, 25 Jun 2018 14:33:40 +0300 Subject: [PATCH] getComparableValue using minimumFractionDigits test: filter comparison uses minimumFractionDigits --- cosmoz-omnitable-column-number.html | 29 +++++++++++++++++++++++++++++ test/range.html | 21 +++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/cosmoz-omnitable-column-number.html b/cosmoz-omnitable-column-number.html index 0855ba23..376c10fa 100644 --- a/cosmoz-omnitable-column-number.html +++ b/cosmoz-omnitable-column-number.html @@ -93,6 +93,35 @@

[[ title ]]

return new Intl.NumberFormat(locale || undefined, options); }, + /** + * Get the comparable value of an item. + * + * @param {Object} item Item to be processed + * @param {String} valuePath Property path + * @returns {Number|void} Valid value or void + */ + getComparableValue(item, valuePath) { + if (item == null) { + return; + } + let value = item; + if (valuePath != null) { + value = this.get(valuePath, item); + } + value = this.toValue(value); + if (value == null) { + return; + } + + const decimals = this.minimumFractionDigits; + if (decimals !== null) { + const d = Math.pow(10, decimals), + temp = parseInt(value * d, 10) / d; + return temp.toFixed(decimals); + } + return value; + }, + renderValue(value, formatter = this.formatter) { const number = this.toNumber(value); if (number == null) { diff --git a/test/range.html b/test/range.html index 6cbbcebf..a0a038ca 100644 --- a/test/range.html +++ b/test/range.html @@ -20,7 +20,7 @@