- fix for decimals in tables in appl form;
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
"mustache": "4.2.0",
|
||||
"object-path-immutable": "4.1.2",
|
||||
"primeicons": "7.0.0",
|
||||
"primereact": "10.9.4",
|
||||
"primereact": "10.9.6",
|
||||
"quill": "2.0.3",
|
||||
"ramda": "0.30.1",
|
||||
"react": "19.1.0",
|
||||
@@ -42,8 +42,8 @@
|
||||
"recharts": "2.15.2",
|
||||
"sockjs-client": "1.6.1",
|
||||
"validate.js": "0.13.1",
|
||||
"zustand": "5.0.3",
|
||||
"zustand-x": "6.1.0"
|
||||
"zustand": "5.0.6",
|
||||
"zustand-x": "6.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.27.0",
|
||||
|
||||
@@ -410,12 +410,12 @@
|
||||
.appPageSection__actions {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
padding: 24px 0 0;
|
||||
padding: 0;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.appPageSection__actions > *:first-child{
|
||||
margin-bottom: 24px;
|
||||
.appPageSection > .appPageSection__actions:first-child {
|
||||
padding-bottom: 24px;
|
||||
}
|
||||
|
||||
.appPageSection .appPageSection__actions:last-of-type {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { InputNumber } from 'primereact/inputnumber';
|
||||
import parseLocaleNumber from '../../../../../../../helpers/parseLocaleNumber';
|
||||
|
||||
const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table }) => {
|
||||
const initialValue = getValue();
|
||||
@@ -19,7 +20,7 @@ const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table })
|
||||
return (
|
||||
<InputNumber
|
||||
disabled={disabled}
|
||||
value={initialValue}
|
||||
value={parseLocaleNumber(initialValue)}
|
||||
/*onValueChange={(e) => onChange(e.value)}*/
|
||||
onFocus={onFocus}
|
||||
onBlur={(e) => onBlur(e.target.value)}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { head, isEmpty, isNil, pathOr, sum } from 'ramda';
|
||||
// components
|
||||
import DefaultCell from './components/DefaultCell';
|
||||
import LastRowCell from './components/LastRowCell';
|
||||
import parseLocaleNumber from '../../../../../helpers/parseLocaleNumber';
|
||||
|
||||
const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn, disabled }) => {
|
||||
const rows = pathOr([], ['rows'], tableValue)
|
||||
@@ -28,7 +29,7 @@ const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn,
|
||||
if (columnCfgData.meta.enableFormula) {
|
||||
const getAllRowsValues = newRowsData.rows
|
||||
.map(row => row[columnId])
|
||||
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
||||
.map(v => parseLocaleNumber(v));
|
||||
|
||||
if (cellValue === 'sum') {
|
||||
total = sum(getAllRowsValues);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { head, isEmpty, isNil, sum } from 'ramda';
|
||||
import { head, isNil, sum } from 'ramda';
|
||||
import getNumberFormatted from '../../../../../../../helpers/getNumberFormatted';
|
||||
import parseLocaleNumber from '../../../../../../../helpers/parseLocaleNumber';
|
||||
|
||||
const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) => {
|
||||
const cellData = head(lastRowCfg.filter(o => !isNil(o[columnId])));
|
||||
@@ -7,7 +8,7 @@ const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) =
|
||||
|
||||
if (columnMeta.enableFormula) {
|
||||
const getAllRowsValues = getColumnDataFn(columnId)
|
||||
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
||||
.map(v => parseLocaleNumber(v));
|
||||
|
||||
if (cellValue === 'sum') {
|
||||
cellValue = getNumberFormatted(sum(getAllRowsValues));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { InputNumber } from 'primereact/inputnumber';
|
||||
import parseLocaleNumber from '../../../../../../../helpers/parseLocaleNumber';
|
||||
|
||||
const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table }) => {
|
||||
const initialValue = getValue();
|
||||
@@ -20,7 +21,7 @@ const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table })
|
||||
return (
|
||||
<InputNumber
|
||||
disabled={disabled}
|
||||
value={initialValue}
|
||||
value={parseLocaleNumber(initialValue)}
|
||||
/*onValueChange={(e) => onChange(e.value)}*/
|
||||
onFocus={onFocus}
|
||||
onBlur={(e) => onBlur(e.target.value)}
|
||||
|
||||
69
src/helpers/parseLocaleNumber.js
Normal file
69
src/helpers/parseLocaleNumber.js
Normal file
@@ -0,0 +1,69 @@
|
||||
export default function parseLocaleNumber(numberString) {
|
||||
// Handle null, undefined, and empty values
|
||||
if (numberString === null || numberString === undefined || numberString === '') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const str = String(numberString).trim();
|
||||
|
||||
if (str === '') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Remove any currency symbols, letters, and other non-numeric characters
|
||||
let cleaned = str.replace(/[^\d.,\-+]/g, '');
|
||||
|
||||
// Handle edge cases
|
||||
if (cleaned === '' || cleaned === '-' || cleaned === '+') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Count dots and commas
|
||||
const dotCount = (cleaned.match(/\./g) || []).length;
|
||||
const commaCount = (cleaned.match(/,/g) || []).length;
|
||||
|
||||
try {
|
||||
// Determine format based on separators
|
||||
if (dotCount === 0 && commaCount === 0) {
|
||||
// Pure integer
|
||||
const result = parseInt(cleaned, 10);
|
||||
return isNaN(result) ? 0 : result;
|
||||
}
|
||||
else if (dotCount === 1 && commaCount === 0) {
|
||||
// US format (123.45)
|
||||
const result = parseFloat(cleaned);
|
||||
return isNaN(result) ? 0 : result;
|
||||
}
|
||||
else if (dotCount === 0 && commaCount === 1) {
|
||||
// Could be European (123,45) or US thousands (1,234)
|
||||
const parts = cleaned.split(',');
|
||||
if (parts.length === 2 && parts[1].length <= 2) {
|
||||
// Likely decimal (123,45)
|
||||
const result = parseFloat(cleaned.replace(',', '.'));
|
||||
return isNaN(result) ? 0 : result;
|
||||
} else {
|
||||
// Likely thousands separator (1,234)
|
||||
const result = parseFloat(cleaned.replace(',', ''));
|
||||
return isNaN(result) ? 0 : result;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Mixed separators - use position to determine
|
||||
const lastDot = cleaned.lastIndexOf('.');
|
||||
const lastComma = cleaned.lastIndexOf(',');
|
||||
|
||||
if (lastDot > lastComma) {
|
||||
// Dot is decimal separator (1,234.56)
|
||||
cleaned = cleaned.replace(/,/g, '');
|
||||
} else {
|
||||
// Comma is decimal separator (1.234,56)
|
||||
cleaned = cleaned.replace(/\./g, '').replace(',', '.');
|
||||
}
|
||||
|
||||
const result = parseFloat(cleaned);
|
||||
return isNaN(result) ? 0 : result;
|
||||
}
|
||||
} catch (error) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user