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 @@
-
+
@@ -76,6 +76,7 @@
amount: { amount: 347, currency: 'USD' }
},
{
+ age: 46.768, // needed in minimumFractionDigits test
amount: { amount: 2581, currency: 'EUR' }
}
];
@@ -124,7 +125,7 @@
test('computes range from values', function (done) {
assert.isObject(column._range);
assert.equal(column._range.min, -11);
- assert.equal(column._range.max, 17);
+ assert.equal(column._range.max, 46.768);
done();
});
@@ -191,6 +192,22 @@
});
column._filterInput = {min: -11, max: 17};
});
+
+ test('filter comparision uses minimumFractionDigits', done => {
+ assert.isNull(column._filterInput.min);
+ assert.isNull(column._filterInput.max);
+
+ const handler = () => {
+ const items = omnitable.sortedFilteredGroupedItems;
+ assert.equal(items.length, 4, 'Expected item coresponding to the age: 46.768 to be in the filtered items.');
+ assert.equal(items[3].amount.amount, 2581); // item coresponding to the age: 46.768 is present on the filtered items.
+
+ omnitable.removeEventListener('sorted-filtered-grouped-items-changed', handler);
+ done();
+ };
+ omnitable.addEventListener('sorted-filtered-grouped-items-changed', handler);
+ column._filterInput = {min: 46.76, max: 46.76};
+ });
});
suite('amount', function () {