diff --git a/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js b/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js index 03add74b..49c14122 100644 --- a/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js +++ b/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js @@ -9,6 +9,11 @@ define(function () { return $filter('date')(date, format); }; }; + this.formatNumber = function (format) { + return function (number) { + return $filter('numeraljs')(number, format); + }; + }; } EntryFormatter.prototype.formatField = function formatField(field) { @@ -19,8 +24,6 @@ define(function () { case 'boolean': case 'choice': case 'choices': - case 'number': - case 'float': case 'string': case 'text': case 'wysiwyg': @@ -34,6 +37,16 @@ define(function () { value: entry.values[field.name()] }; }; + case 'number': + case 'float': + var format = field.format(); + var formatNumber = this.formatNumber(format); + return function (entry) { + return { + name: label, + value: formatNumber(entry.values[field.name()]) + }; + }; case 'date': case 'datetime': var format = field.format(); diff --git a/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js b/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js index eb278a40..475d4609 100644 --- a/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js +++ b/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js @@ -31,10 +31,12 @@ describe("Service: EntryFormatter.getFormatter formatter", function () { var formatter = entryFormatter.getFormatter([getField({ type: 'number', name: 'number', - label: 'Number' + label: 'Number', + format: '0.000%' })]); + var number = 56; - expect(formatter({values: {number: 5}})).toEqual({Number: 5}); + expect(formatter({ values: { number: number } })).toEqual({ Number: { date: 56, format: '0.000%' } }); }); it('formatter should format field of type text', function () {