fix: footer(합계) 작업 중
This commit is contained in:
@@ -10,6 +10,16 @@ import { useAlertStore } from "@/shared/lib";
|
||||
import { Button } from "@common/components";
|
||||
import { useTabStore } from "@/store/tab-store"
|
||||
|
||||
// RealGrid 타입 확장
|
||||
declare module "realgrid" {
|
||||
interface GridView {
|
||||
setOptions(options: {
|
||||
footer?: { visible?: boolean };
|
||||
summaryMode?: 'aggregate' | 'statistical' | 'none';
|
||||
}): void;
|
||||
}
|
||||
}
|
||||
|
||||
// Window 인터페이스 확장
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -32,7 +42,28 @@ const DataGrid = ({ columnInfo, rows = [], rowStartNum, isExcelImport = true, fi
|
||||
const activeTabId = useTabStore((state) => state.activeTabId);
|
||||
const menuList = useTabStore((state) => state.menuList);
|
||||
|
||||
const [rowData, setRowData] = useState<Record<string, string>[]>([]);
|
||||
const [rowData, setRowData] = useState<Record<string, string | number>[]>([]);
|
||||
|
||||
// footer가 있는 컬럼의 데이터를 숫자로 변환
|
||||
const convertNumericData = (data: Record<string, string>[]): Record<string, string | number>[] => {
|
||||
const footerColumns = columns.filter(col => col.footer);
|
||||
const footerFieldNames = new Set(footerColumns.map(col => col.fieldName));
|
||||
|
||||
return data.map(row => {
|
||||
const convertedRow: Record<string, string | number> = { ...row };
|
||||
footerFieldNames.forEach(fieldName => {
|
||||
const value = row[fieldName];
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
// 쉼표 제거 후 숫자로 변환
|
||||
const numericValue = Number(String(value).replace(/,/g, ''));
|
||||
if (!isNaN(numericValue)) {
|
||||
convertedRow[fieldName] = numericValue;
|
||||
}
|
||||
}
|
||||
});
|
||||
return convertedRow;
|
||||
});
|
||||
};
|
||||
|
||||
const exportExcel = () => {
|
||||
if (rowData.length === 0) {
|
||||
@@ -152,7 +183,8 @@ const DataGrid = ({ columnInfo, rows = [], rowStartNum, isExcelImport = true, fi
|
||||
}
|
||||
}
|
||||
|
||||
setRowData(dataRows);
|
||||
const convertedDataRows = convertNumericData(dataRows);
|
||||
setRowData(convertedDataRows);
|
||||
} catch (error) {
|
||||
console.error('엑셀 파일 파싱 오류:', error);
|
||||
alert('엑셀 파일 파싱 중 오류가 발생했습니다.');
|
||||
@@ -187,8 +219,11 @@ const DataGrid = ({ columnInfo, rows = [], rowStartNum, isExcelImport = true, fi
|
||||
|
||||
(gridView.displayOptions as DisplayOptions).fitStyle = GridFitStyle.EVEN;
|
||||
gridView.header.height = 60;
|
||||
if (rows.length > 0) {
|
||||
setRowData(rows);
|
||||
|
||||
// footer가 있는 컬럼이 있으면 footer 높이 설정
|
||||
const hasFooter = columns.some(col => col.footer);
|
||||
if (hasFooter) {
|
||||
gridView.footer.height = 40;
|
||||
}
|
||||
|
||||
// 고정 컬럼 설정
|
||||
@@ -197,7 +232,27 @@ const DataGrid = ({ columnInfo, rows = [], rowStartNum, isExcelImport = true, fi
|
||||
colCount: fixedColumns,
|
||||
});
|
||||
}
|
||||
}, [rows, columns, columnLayout, fixedColumns]);
|
||||
|
||||
gridView.setOptions({
|
||||
summaryMode: "aggregate"
|
||||
});
|
||||
|
||||
// footer의 valueCallback 설정
|
||||
columns.forEach(col => {
|
||||
if (col.footer && col.footer.valueCallback) {
|
||||
const column = gridView.columnByName(col.name);
|
||||
if (column && column.footer) {
|
||||
(column.footer as { valueCallback?: typeof col.footer.valueCallback }).valueCallback = col.footer.valueCallback;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (rows.length > 0) {
|
||||
const convertedRows = convertNumericData(rows);
|
||||
setRowData(convertedRows);
|
||||
}
|
||||
|
||||
}, [rows, columns, columnLayout, fixedColumns, rowData]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-[0.6rem] mx-[0.6rem]">
|
||||
@@ -233,6 +288,11 @@ const DataGrid = ({ columnInfo, rows = [], rowStartNum, isExcelImport = true, fi
|
||||
name={column.name}
|
||||
fieldName={column.fieldName}
|
||||
header={column.header}
|
||||
footer={column.footer ? {
|
||||
text: column.footer.text,
|
||||
expression: column.footer.expression,
|
||||
numberFormat: column.footer.numberFormat,
|
||||
} : undefined}
|
||||
// autoFilter={true}
|
||||
/>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user