From 680da9b323db8b8d7cf27c674ab0016ec87bfe81 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 4 Nov 2025 07:48:00 +0000
Subject: (임수민) 구매 점검 테스트 요청사항 수정 (11/02)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/rfq-last/table/rfq-table.tsx | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

(limited to 'lib/rfq-last/table/rfq-table.tsx')

diff --git a/lib/rfq-last/table/rfq-table.tsx b/lib/rfq-last/table/rfq-table.tsx
index 9f78f578..162dd343 100644
--- a/lib/rfq-last/table/rfq-table.tsx
+++ b/lib/rfq-last/table/rfq-table.tsx
@@ -215,6 +215,9 @@ export function RfqTable({
     expandedRows: []
   }), [getSearchParam, parseSearchParam]);
 
+  // 탭별로 독립적인 tableId 사용 (정렬 상태 분리)
+  const tableId = React.useMemo(() => `rfq-table-${rfqCategory}`, [rfqCategory]);
+
   const {
     presets,
     activePresetId,
@@ -227,7 +230,7 @@ export function RfqTable({
     setDefaultPreset,
     renamePreset,
     getCurrentSettings,
-  } = useTablePresets<RfqsLastView>('rfq-table', initialSettings);
+  } = useTablePresets<RfqsLastView>(tableId, initialSettings);
 
   // 컬럼 정의
   const columns = React.useMemo(() => {
@@ -305,11 +308,25 @@ export function RfqTable({
 
   const currentSettings = React.useMemo(() => getCurrentSettings(), [getCurrentSettings]);
 
-  const initialState = React.useMemo(() => ({
-    sorting: initialSettings.sort.filter((s: any) => columns.some((c: any) => ("accessorKey" in c ? c.accessorKey : c.id) === s.id)),
-    columnVisibility: currentSettings.columnVisibility,
-    columnPinning: currentSettings.pinnedColumns,
-  }), [columns, currentSettings, initialSettings.sort]);
+  // 탭별로 독립적인 정렬 상태 관리
+  // rfqCategory가 변경되면 정렬 상태를 재계산하여 탭 간 정렬 충돌 방지
+  const initialState = React.useMemo(() => {
+    // 현재 탭의 컬럼에 존재하는 정렬만 유효한 것으로 필터링
+    const validSorting = initialSettings.sort.filter((s: any) => 
+      columns.some((c: any) => ("accessorKey" in c ? c.accessorKey : c.id) === s.id)
+    );
+    
+    // 유효한 정렬이 없으면 기본 정렬 사용
+    const sorting = validSorting.length > 0 
+      ? validSorting 
+      : [{ id: "createdAt", desc: true }];
+    
+    return {
+      sorting,
+      columnVisibility: currentSettings.columnVisibility,
+      columnPinning: currentSettings.pinnedColumns,
+    };
+  }, [columns, currentSettings, initialSettings.sort, rfqCategory]);
 
   const { table } = useDataTable({
     data: tableData.data,
-- 
cgit v1.2.3

