[st] - 입력단 작업 완료
This commit is contained in:
@@ -3,9 +3,27 @@ import { ValueType } from "realgrid"
|
||||
|
||||
import RealGrid, { GridFitStyle } from "realgrid"
|
||||
import { RealGridReact, RGDataColumn } from "realgrid-react"
|
||||
import type { DataGridProps, RealGridColumnInfo, GridViewWithSetColumns, FooterItemWithCallback, CellStyleCallback } from "../type/DataGrid.type"
|
||||
import type { DataGridProps, RealGridColumnInfo, GridViewWithSetColumns, FooterItemWithCallback, CellStyleCallback, CellStyleCallbackResult, CellStyleCallbackParams } from "../type/DataGrid.type"
|
||||
import { getComputedValueCallback } from "@/components/util/grid/computedFieldCallbacks"
|
||||
|
||||
function mergeCellStyleCallbackResult(
|
||||
baseStyleName: string | undefined,
|
||||
extra: CellStyleCallbackResult | undefined,
|
||||
): CellStyleCallbackResult {
|
||||
if (!extra) {
|
||||
return baseStyleName ? { styleName: baseStyleName } : {};
|
||||
}
|
||||
if (typeof extra === "string") {
|
||||
const styleName = [extra, baseStyleName].filter(Boolean).join(" ");
|
||||
return styleName ? { styleName } : {};
|
||||
}
|
||||
const styleName = [extra.styleName, baseStyleName].filter(Boolean).join(" ");
|
||||
return {
|
||||
...extra,
|
||||
...(styleName ? { styleName } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// RealGrid 타입 확장
|
||||
declare module "realgrid" {
|
||||
interface GridView {
|
||||
@@ -411,18 +429,33 @@ const CompactDataGrid = ({
|
||||
columns.forEach((column) => {
|
||||
const baseStyleName = column.styleName;
|
||||
const gridCol = currentGridView.columnByName(column.name) as {
|
||||
styleCallback?: (g: unknown, dataCell: { itemIndex?: number; index?: { itemIndex?: number }; dataField?: string; fieldName?: string }) => string;
|
||||
styleCallback?: (
|
||||
g: unknown,
|
||||
dataCell: {
|
||||
itemIndex?: number;
|
||||
index?: { itemIndex?: number };
|
||||
dataField?: string;
|
||||
fieldName?: string;
|
||||
},
|
||||
) => CellStyleCallbackResult;
|
||||
} | null;
|
||||
if (gridCol) {
|
||||
gridCol.styleCallback = (_g, dataCell) => {
|
||||
gridCol.styleCallback = (grid, dataCell) => {
|
||||
const itemIndex = dataCell?.index?.itemIndex ?? dataCell?.itemIndex ?? -1;
|
||||
const fieldName = (dataCell?.dataField ?? dataCell?.fieldName ?? column.fieldName) ?? '';
|
||||
const fieldName =
|
||||
(dataCell?.dataField ?? dataCell?.fieldName ?? column.fieldName) ?? "";
|
||||
const data = rowDataRef.current;
|
||||
if (itemIndex < 0 || itemIndex >= data.length) return baseStyleName ?? '';
|
||||
if (itemIndex < 0 || itemIndex >= data.length) {
|
||||
return mergeCellStyleCallbackResult(baseStyleName, undefined);
|
||||
}
|
||||
const row = data[itemIndex] as Record<string, string | number>;
|
||||
const extra = cellStyleCallbackRef.current?.({ rowIndex: itemIndex, fieldName, row });
|
||||
if (!extra) return baseStyleName ?? '';
|
||||
return baseStyleName ? `${extra} ${baseStyleName}` : extra;
|
||||
const extra = cellStyleCallbackRef.current?.({
|
||||
rowIndex: itemIndex,
|
||||
fieldName,
|
||||
row,
|
||||
grid: grid as CellStyleCallbackParams["grid"],
|
||||
});
|
||||
return mergeCellStyleCallbackResult(baseStyleName, extra);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,6 +11,8 @@ import { Button } from "@common/components";
|
||||
|
||||
import type {
|
||||
CellStyleCallback,
|
||||
CellStyleCallbackParams,
|
||||
CellStyleCallbackResult,
|
||||
CellTooltipCallback,
|
||||
ColumnLayoutItem,
|
||||
DataGridProps,
|
||||
@@ -28,6 +30,24 @@ import {
|
||||
} from "@/components/util/gridExcelExport";
|
||||
import { useTabStore } from "@/store/tab-store";
|
||||
|
||||
function mergeCellStyleCallbackResult(
|
||||
baseStyleName: string | undefined,
|
||||
extra: CellStyleCallbackResult | undefined,
|
||||
): CellStyleCallbackResult {
|
||||
if (!extra) {
|
||||
return baseStyleName ? { styleName: baseStyleName } : {};
|
||||
}
|
||||
if (typeof extra === "string") {
|
||||
const styleName = [extra, baseStyleName].filter(Boolean).join(" ");
|
||||
return styleName ? { styleName } : {};
|
||||
}
|
||||
const styleName = [extra.styleName, baseStyleName].filter(Boolean).join(" ");
|
||||
return {
|
||||
...extra,
|
||||
...(styleName ? { styleName } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// RealGrid 타입 확장
|
||||
declare module "realgrid" {
|
||||
interface GridView {
|
||||
@@ -570,6 +590,14 @@ function buildFieldsFromColumns(
|
||||
"denominatorQuotient" in col.computed &&
|
||||
col.computed.numeratorQuotient.length === 2 &&
|
||||
col.computed.denominatorQuotient.length === 2;
|
||||
const hasQuotientTimesMultiplierPercent =
|
||||
col.computed.type === "quotientTimesMultiplierPercent" &&
|
||||
"numeratorField" in col.computed &&
|
||||
"denominatorField" in col.computed &&
|
||||
"multiplierField" in col.computed &&
|
||||
Boolean(col.computed.numeratorField) &&
|
||||
Boolean(col.computed.denominatorField) &&
|
||||
Boolean(col.computed.multiplierField);
|
||||
if (
|
||||
hasFields ||
|
||||
hasNumeratorDenominator ||
|
||||
@@ -581,7 +609,8 @@ function buildFieldsFromColumns(
|
||||
hasPumpGrossPpqty ||
|
||||
hasBodPrcsRt ||
|
||||
hasSumPerTenThousand ||
|
||||
hasQuotientRatioPercent
|
||||
hasQuotientRatioPercent ||
|
||||
hasQuotientTimesMultiplierPercent
|
||||
) {
|
||||
const computedCallback = getComputedValueCallback(
|
||||
col.computed,
|
||||
@@ -1922,7 +1951,7 @@ const DataGrid = ({
|
||||
dataField?: string;
|
||||
fieldName?: string;
|
||||
},
|
||||
) => string;
|
||||
) => CellStyleCallbackResult;
|
||||
renderer?: { showTooltip?: boolean };
|
||||
} | null;
|
||||
if (gridCol) {
|
||||
@@ -1961,7 +1990,7 @@ const DataGrid = ({
|
||||
{ showTooltip: true },
|
||||
);
|
||||
}
|
||||
gridCol.styleCallback = (_g, dataCell) => {
|
||||
gridCol.styleCallback = (grid, dataCell) => {
|
||||
const itemIndex =
|
||||
dataCell?.index?.itemIndex ??
|
||||
dataCell?.itemIndex ??
|
||||
@@ -1974,8 +2003,12 @@ const DataGrid = ({
|
||||
if (
|
||||
itemIndex < 0 ||
|
||||
itemIndex >= data.length
|
||||
)
|
||||
return baseStyleName ?? "";
|
||||
) {
|
||||
return mergeCellStyleCallbackResult(
|
||||
baseStyleName,
|
||||
undefined,
|
||||
);
|
||||
}
|
||||
const row = data[itemIndex] as Record<
|
||||
string,
|
||||
string | number
|
||||
@@ -1985,11 +2018,12 @@ const DataGrid = ({
|
||||
rowIndex: itemIndex,
|
||||
fieldName,
|
||||
row,
|
||||
grid: grid as CellStyleCallbackParams["grid"],
|
||||
});
|
||||
if (!extra) return baseStyleName ?? "";
|
||||
return baseStyleName
|
||||
? `${extra} ${baseStyleName}`
|
||||
: extra;
|
||||
return mergeCellStyleCallbackResult(
|
||||
baseStyleName,
|
||||
extra,
|
||||
);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,9 +10,27 @@ import { useAlertStore } from "@/shared/lib";
|
||||
import { Tabs, TabsContent,TabsList, TabsTrigger } from "@common/components";
|
||||
import { Button } from "@common/components";
|
||||
|
||||
import type { CellStyleCallback,ColumnConfig, ColumnInfo, ColumnLayoutItem, FooterItemWithCallback, GridViewWithSetColumns, RealGridColumnInfo, TabDataGridProps } from "../type/DataGrid.type"
|
||||
import type { CellStyleCallback, CellStyleCallbackParams, CellStyleCallbackResult, ColumnConfig, ColumnInfo, ColumnLayoutItem, FooterItemWithCallback, GridViewWithSetColumns, RealGridColumnInfo, TabDataGridProps } from "../type/DataGrid.type"
|
||||
|
||||
import GridTopActionButton from "./GridTopActionButton";
|
||||
|
||||
function mergeCellStyleCallbackResult(
|
||||
baseStyleName: string | undefined,
|
||||
extra: CellStyleCallbackResult | undefined,
|
||||
): CellStyleCallbackResult {
|
||||
if (!extra) {
|
||||
return baseStyleName ? { styleName: baseStyleName } : {};
|
||||
}
|
||||
if (typeof extra === "string") {
|
||||
const styleName = [extra, baseStyleName].filter(Boolean).join(" ");
|
||||
return styleName ? { styleName } : {};
|
||||
}
|
||||
const styleName = [extra.styleName, baseStyleName].filter(Boolean).join(" ");
|
||||
return {
|
||||
...extra,
|
||||
...(styleName ? { styleName } : {}),
|
||||
};
|
||||
}
|
||||
import SplitDataGrid from "./SplitDataGrid";
|
||||
|
||||
import { getComputedValueCallback } from "@/components/util/grid/computedFieldCallbacks"
|
||||
@@ -73,10 +91,12 @@ function safeGridViewRefresh(gv: { refresh?: () => void } | null | undefined) {
|
||||
function safeColumnByName(
|
||||
gv: { columnByName?: (name: string) => unknown } | null | undefined,
|
||||
name: string,
|
||||
): { styleCallback?: (g: unknown, dataCell: Record<string, unknown>) => string } | null {
|
||||
): { styleCallback?: (g: unknown, dataCell: Record<string, unknown>) => CellStyleCallbackResult } | null {
|
||||
if (!gv?.columnByName) return null;
|
||||
try {
|
||||
const col = gv.columnByName(name) as { styleCallback?: (g: unknown, dataCell: Record<string, unknown>) => string } | null;
|
||||
const col = gv.columnByName(name) as {
|
||||
styleCallback?: (g: unknown, dataCell: Record<string, unknown>) => CellStyleCallbackResult;
|
||||
} | null;
|
||||
return col ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
@@ -296,7 +316,7 @@ const TabDataGrid = ({
|
||||
const gridCol = safeColumnByName(gv, column.name);
|
||||
if (!gridCol) continue;
|
||||
const baseStyleName = column.styleName;
|
||||
gridCol.styleCallback = (_g, dataCell) => {
|
||||
gridCol.styleCallback = (grid, dataCell) => {
|
||||
const dc = dataCell as {
|
||||
itemIndex?: number;
|
||||
index?: { itemIndex?: number };
|
||||
@@ -307,16 +327,16 @@ const TabDataGrid = ({
|
||||
const fieldName = dc?.dataField ?? dc?.fieldName ?? column.fieldName;
|
||||
const data = rowDataMapRef.current.get(tabKey) || [];
|
||||
if (itemIndex < 0 || itemIndex >= data.length) {
|
||||
return baseStyleName ?? "";
|
||||
return mergeCellStyleCallbackResult(baseStyleName, undefined);
|
||||
}
|
||||
const row = data[itemIndex] as Record<string, string | number>;
|
||||
const extra = cellStyleCallbackRef.current?.({
|
||||
rowIndex: itemIndex,
|
||||
fieldName,
|
||||
row,
|
||||
grid: grid as CellStyleCallbackParams["grid"],
|
||||
});
|
||||
if (!extra) return baseStyleName ?? "";
|
||||
return baseStyleName ? `${extra} ${baseStyleName}` : extra;
|
||||
return mergeCellStyleCallbackResult(baseStyleName, extra);
|
||||
};
|
||||
attachedCount += 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user