Created
March 24, 2015 10:29
-
-
Save MatthewBarker/936edbf0c1f0e04f5d2f to your computer and use it in GitHub Desktop.
Knockout-Kendo number custom binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ko.bindingHandlers.number = { | |
| update: function(element, valueAccessor, allBindingsAccessor) { | |
| var value = ko.utils.unwrapObservable(valueAccessor()), | |
| precision = ko.utils.unwrapObservable(allBindingsAccessor().precision) || ko.bindingHandlers.number.defaultPrecision, | |
| format = '###,###,###,###.' + '0'.repeat(precision) + ';(###,###,###,###.' + '0'.repeat(precision) + ')', | |
| formattedValue = kendo.toString(parseFloat(value, 10), format); | |
| ko.bindingHandlers.text.update(element, function() { return formattedValue; }); | |
| }, | |
| defaultPrecision: 0 | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment