Files
frontend/apps/st/src/components/util/grid/footerSummary.ts
T

22 lines
780 B
TypeScript

import type { GridView, DataColumn } from "@/components/type/DataGrid.type";
export const getFooterSummary = (grid: GridView, column: DataColumn) => {
// 데이터 소스에서 직접 합계 계산
const dataSource = grid.getDataSource();
const rowCount = dataSource.getRowCount();
let sum = 0;
for (let i = 0; i < rowCount; i++) {
const cellValue = dataSource.getValue(i, column.fieldName);
// 문자열인 경우 숫자로 변환
const numericValue = typeof cellValue === 'string'
? Number(String(cellValue).replace(/,/g, ''))
: Number(cellValue);
if (!isNaN(numericValue) && numericValue !== null && numericValue !== undefined) {
sum += numericValue;
}
}
return sum;
};