финансовый формат для ячеек
This commit is contained in:
parent
bafae2ca58
commit
bb74f511af
@ -4,7 +4,6 @@ import styled from '@emotion/styled';
|
|||||||
import { useRealtime } from '../../contexts/RealtimeContext';
|
import { useRealtime } from '../../contexts/RealtimeContext';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
|
||||||
|
|
||||||
const ContainerForText = styled.span`
|
const ContainerForText = styled.span`
|
||||||
display: -webkit-box;
|
display: -webkit-box;
|
||||||
-webkit-box-orient: vertical;
|
-webkit-box-orient: vertical;
|
||||||
@ -43,9 +42,30 @@ const highlightText = (text, searchQuery) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Функция для форматирования числа в финансовый формат
|
||||||
|
const formatNumber = (value) => {
|
||||||
|
if (value === null || value === undefined || value === '') return String(value || '');
|
||||||
|
|
||||||
|
const num = Number(value);
|
||||||
|
if (isNaN(num)) return String(value);
|
||||||
|
|
||||||
|
// Форматируем число с 1 знаком после запятой и разделением по 3 цифры
|
||||||
|
return num.toLocaleString('ru-RU', {
|
||||||
|
minimumFractionDigits: 1,
|
||||||
|
maximumFractionDigits: 1,
|
||||||
|
useGrouping: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const Cell = React.memo(({ cell, row, column, onClick, globalFilter, backgroundColor, color, isEditable }) => {
|
const Cell = React.memo(({ cell, row, column, onClick, globalFilter, backgroundColor, color, isEditable }) => {
|
||||||
const cellValue = cell.getValue();
|
const cellValue = cell.getValue();
|
||||||
const textValue = String(cellValue || '');
|
let textValue = String(cellValue || '');
|
||||||
|
|
||||||
|
// Проверяем, является ли значение числом, и форматируем его
|
||||||
|
const isNumeric = !isNaN(Number(cellValue)) && cellValue !== null && cellValue !== undefined && cellValue !== '';
|
||||||
|
if (isNumeric) {
|
||||||
|
textValue = formatNumber(cellValue);
|
||||||
|
}
|
||||||
|
|
||||||
// Подсвечиваем текст с учетом поискового запроса
|
// Подсвечиваем текст с учетом поискового запроса
|
||||||
const highlightedContent = useMemo(() => {
|
const highlightedContent = useMemo(() => {
|
||||||
@ -58,7 +78,6 @@ const Cell = React.memo(({ cell, row, column, onClick, globalFilter, backgroundC
|
|||||||
cursor: 'not-allowed',
|
cursor: 'not-allowed',
|
||||||
} : {};
|
} : {};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="cell"
|
className="cell"
|
||||||
@ -87,4 +106,4 @@ const Cell = React.memo(({ cell, row, column, onClick, globalFilter, backgroundC
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Cell;
|
export default Cell;
|
||||||
Loading…
x
Reference in New Issue
Block a user