mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
18 lines
853 B
TypeScript
18 lines
853 B
TypeScript
|
import {FieldOptions} from 'app/client/widgets/NewBaseEditor';
|
||
|
import {NTextEditor} from 'app/client/widgets/NTextEditor';
|
||
|
|
||
|
export class NumericEditor extends NTextEditor {
|
||
|
constructor(protected options: FieldOptions) {
|
||
|
if (!options.editValue && typeof options.cellValue === 'number') {
|
||
|
// If opening a number for editing, we render it using the basic string representation (e.g.
|
||
|
// no currency symbols or groupings), but it's important to use the right locale so that the
|
||
|
// number can be parsed back (e.g. correct decimal separator).
|
||
|
const locale = options.field.documentSettings.peek().locale;
|
||
|
const fmt = new Intl.NumberFormat(locale, {useGrouping: false, maximumFractionDigits: 20});
|
||
|
const editValue = fmt.format(options.cellValue);
|
||
|
options = {...options, editValue};
|
||
|
}
|
||
|
super(options);
|
||
|
}
|
||
|
}
|