bryntum / support

An issues-only repository for the Bryntum project management component suite which includes powerful Grid, Scheduler, Calendar, Kanban Task Board and Gantt chart components all built in pure JS / CSS / TypeScript
https://www.bryntum.com
54 stars 6 forks source link

Number column needs formatting information #50

Closed isglass closed 4 years ago

isglass commented 4 years ago

The framework needs a general purpose number formatting function which can be internationalized. Probably in Core/helper/StringHelper. Should use browser formatting https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat. Locale can be read from same setting as DateHelper uses (key DateHelper.locale in localization files)

Probably needs a string-based format token for ease of use.

NumberColumn should then use it in its defaultRenderer.

{ type : 'number', field : 'value', text : 'Value', format : '????' }

Right now, any non-integer value can be displayed by javascript's default toString which is unsuitable for a UI.

image

Transfered from Assembla #6246.

dongryphon commented 4 years ago

When cell editing is used, it seems like passing the NumberColumn's format on to the NumberField would be appropriate. I have done so on my PR (https://github.com/bryntum/bryntum-suite/pull/364). There is a test failure but I think the resolution would be a change to the test as well as the underlying widget.

dongryphon commented 4 years ago

The NumberColumn now has a format config which defaults to the locale's default format. This format can be specified as a template string (such as 9,9.99## to enable thousand separators, minimum of 2 decimal digits and max of 4). It can also be a config object for the NumberFormat class.

This config is passed to the NumberField when cell editing is active.

The NumberFormat class supports the same options as Intl.NumberFormat but also provides a parse() method that uses the proper decimal and digit grouping character.