Skip to content

Commit

Permalink
format number for export
Browse files Browse the repository at this point in the history
  • Loading branch information
ThieryMichel committed Jul 30, 2015
1 parent fff7044 commit 1cf3373
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/javascripts/ng-admin/Crud/misc/EntryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -19,8 +24,6 @@ define(function () {
case 'boolean':
case 'choice':
case 'choices':
case 'number':
case 'float':
case 'string':
case 'text':
case 'wysiwyg':
Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 1cf3373

Please sign in to comment.