Skip to content

Commit 39be286

Browse files
committed
feat: num editor
1 parent ee7a12b commit 39be286

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@revolist/revogrid-column-numeral",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"description": "Number column type for RevoGrid system based on numeraljs",
55
"main": "./dist/revo-column-number.umd.cjs",
66
"module": "./dist/revo-column-number.mjs",

src/index.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import type {
2-
VNode,
3-
CellProps,
4-
ColumnDataSchemaModel,
5-
HyperFunc,
6-
ColumnProperties,
7-
ColumnRegular,
1+
import {
2+
type VNode,
3+
type CellProps,
4+
type ColumnDataSchemaModel,
5+
type HyperFunc,
6+
type ColumnType,
7+
type ColumnRegular,
8+
TextEditor,
89
} from '@revolist/revogrid';
910
import numeral, { Numeral } from 'numeral';
1011

1112
const defaultFormat = '0,0[.]00';
13+
/**
14+
* Editor which returns value as number
15+
*/
16+
class EditCell extends TextEditor {
17+
getValue(): any {
18+
const value = this.editInput?.value;
19+
const parsedValue = parseFloat(value);
20+
return isNaN(parsedValue) ? value : parsedValue;
21+
}
22+
}
1223

13-
export default class NumberColumnType implements ColumnProperties {
24+
export default class NumberColumnType implements ColumnType {
1425
private numberFormat = defaultFormat;
1526
constructor(
1627
format?: string,
@@ -20,6 +31,7 @@ export default class NumberColumnType implements ColumnProperties {
2031
this.numberFormat = format;
2132
}
2233
}
34+
editor = EditCell;
2335
columnProperties = (): CellProps => ({ class: { ['align-center']: true } });
2436

2537
cellProperties = (): CellProps => ({ class: { ['align-right']: true } });

0 commit comments

Comments
 (0)