Fix "number.toFixed is not function" JS error.

Issue:
We got the following error in console log
"number.toFixed is not function"

Steps to reproduce:
1) Click on statistics tab.
1) Select any database node.
2) then select Databases collection node.
3) The above error will appear into console.

Reason:
I discussed the issue with @Murtaza and here we are explicitly
converting values at server side to string as JSON do not directly
support NaN & Infinity values. Because of which NumberFormatter receives
values of type string and breaks.

Solution:
Overrides the NumberFormatter to support NaN & Infinity values.
and we need to parse the values again in float at client side.
This commit is contained in:
Surinder Kumar
2016-06-23 12:46:48 +01:00
committed by Dave Page
parent 4983eb2f1c
commit 09569a23bd

View File

@@ -884,6 +884,26 @@
})
});
/*
* Override NumberFormatter to support NaN, Infinity values.
* On client side, JSON do not directly support NaN & Infinity,
* we explicitly converted it into string format at server side
* and we need to parse it again in float at client side.
*/
_.extend(Backgrid.NumberFormatter.prototype, {
fromRaw: function (number, model) {
if (_.isNull(number) || _.isUndefined(number)) return '';
number = parseFloat(number).toFixed(~~this.decimals);
var parts = number.split('.');
var integerPart = parts[0];
var decimalPart = parts[1] ? (this.decimalSeparator || '.') + parts[1] : '';
return integerPart.replace(this.HUMANIZED_NUM_RE, '$1' + this.orderSeparator) + decimalPart;
}
});
return Backgrid;
}));