Skip to content

Commit

Permalink
Add support for thousand and decimal separators in number cell (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
anguedev committed Feb 10, 2023
1 parent cc463a9 commit c9e1f3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Expand Up @@ -12,6 +12,8 @@ interface Props {
readonly validatedSelection?: SelectionRange;
readonly fixedDecimals?: number;
readonly allowNegative?: boolean;
readonly thousandSeparator?: boolean | string;
readonly decimalSeparator?: string;
}

function getDecimalSeparator() {
Expand All @@ -28,7 +30,7 @@ function getThousandSeprator() {
}

const NumberOverlayEditor: React.FunctionComponent<Props> = p => {
const { value, onChange, disabled, highlight, validatedSelection, fixedDecimals, allowNegative } = p;
const { value, onChange, disabled, highlight, validatedSelection, fixedDecimals, allowNegative, thousandSeparator, decimalSeparator } = p;

const inputRef = React.useRef<HTMLInputElement>();

Expand All @@ -51,8 +53,8 @@ const NumberOverlayEditor: React.FunctionComponent<Props> = p => {
disabled={disabled === true}
decimalScale={fixedDecimals}
allowNegative={allowNegative}
thousandSeparator={getThousandSeprator()}
decimalSeparator={getDecimalSeparator()}
thousandSeparator={thousandSeparator ?? getThousandSeprator()}
decimalSeparator={decimalSeparator ?? getDecimalSeparator()}
value={Object.is(value, -0) ? "-" : value ?? ""}
// decimalScale={3}
// prefix={"$"}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/data-grid/cells/number-cell.tsx
Expand Up @@ -31,6 +31,8 @@ export const numberCellRenderer: InternalCellRenderer<NumberCell> = {
value={value.data}
fixedDecimals={value.fixedDecimals}
allowNegative={value.allowNegative}
thousandSeparator={value.thousandSeparator}
decimalSeparator={value.decimalSeparator}
validatedSelection={validatedSelection}
onChange={x =>
onChange({
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/data-grid/data-grid-types.ts
Expand Up @@ -442,6 +442,8 @@ export interface NumberCell extends BaseGridCell {
readonly readonly?: boolean;
readonly fixedDecimals?: number;
readonly allowNegative?: boolean;
readonly thousandSeparator?: boolean | string;
readonly decimalSeparator?: string;
}

/** @category Cells */
Expand Down

0 comments on commit c9e1f3d

Please sign in to comment.