[st] - fix: 오류 수정 및 누락 기능 추가
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import type { ColumnConfig } from "@/components/type/DataGrid.type";
|
||||
import type { GridView } from "realgrid";
|
||||
|
||||
export type ExcelExportVisibilitySnapshot = Map<string, boolean>;
|
||||
|
||||
/** 엑셀보내기 직전: 제외 컬럼 숨김, 그리드용 숨김(visible:false) 컬럼은 export에만 표시 */
|
||||
export function prepareGridColumnsForExcelExport(
|
||||
gridView: GridView,
|
||||
columns: ColumnConfig[],
|
||||
): ExcelExportVisibilitySnapshot {
|
||||
const excludedNames = new Set(
|
||||
columns.filter((c) => c.excludeFromExcelExport).map((c) => c.name),
|
||||
);
|
||||
const snapshot = new Map<string, boolean>();
|
||||
|
||||
columns.forEach((col) => {
|
||||
const gridCol = gridView.columnByName?.(col.name);
|
||||
if (!gridCol) return;
|
||||
|
||||
const wasVisible = gridCol.visible !== false;
|
||||
snapshot.set(col.name, wasVisible);
|
||||
|
||||
if (excludedNames.has(col.name)) {
|
||||
gridCol.visible = false;
|
||||
} else if (col.visible === false) {
|
||||
gridCol.visible = true;
|
||||
}
|
||||
});
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
export function restoreGridColumnsAfterExcelExport(
|
||||
gridView: GridView,
|
||||
snapshot: ExcelExportVisibilitySnapshot,
|
||||
): void {
|
||||
snapshot.forEach((visible, name) => {
|
||||
const gridCol = gridView.columnByName?.(name);
|
||||
if (gridCol) gridCol.visible = visible;
|
||||
});
|
||||
}
|
||||
|
||||
export function shouldPrepareColumnsForExcelExport(columns: ColumnConfig[]): boolean {
|
||||
return columns.some((c) => c.excludeFromExcelExport || c.visible === false);
|
||||
}
|
||||
Reference in New Issue
Block a user