From 3f78fcd0ebf6fab13871d16d47f1c7a32717426f Mon Sep 17 00:00:00 2001 From: "troy.lty" Date: Thu, 31 Oct 2019 20:08:39 +0800 Subject: [PATCH 1/3] fix: useAntdTable won't change page on first switch --- src/useAntdTable/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/useAntdTable/index.ts b/src/useAntdTable/index.ts index 23100188c1..4ba1008071 100644 --- a/src/useAntdTable/index.ts +++ b/src/useAntdTable/index.ts @@ -348,8 +348,14 @@ function useAntdTable( s: SorterResult = {} as SorterResult, ) => { /* 如果 filter,或者 sort 变化,就初始化 current */ + const realFilter = JSON.parse(JSON.stringify(f)); + Object.entries(realFilter).forEach( item => { + if(item[1] === null) { + delete (realFilter as any)[item[0]]; + } + }); const needReload = - !isEqual(f, state.filters) || + !isEqual(realFilter, state.filters) || s.field !== state.sorter.field || s.order !== state.sorter.order; dispatch({ From 455091ac75235b01824d5a7d0d9add239bbb2fbd Mon Sep 17 00:00:00 2001 From: "troy.lty" Date: Thu, 31 Oct 2019 20:12:11 +0800 Subject: [PATCH 2/3] fix: typescript definition --- src/useAntdTable/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/useAntdTable/index.ts b/src/useAntdTable/index.ts index 4ba1008071..fe8a5390b6 100644 --- a/src/useAntdTable/index.ts +++ b/src/useAntdTable/index.ts @@ -348,10 +348,10 @@ function useAntdTable( s: SorterResult = {} as SorterResult, ) => { /* 如果 filter,或者 sort 变化,就初始化 current */ - const realFilter = JSON.parse(JSON.stringify(f)); + const realFilter = {...f}; Object.entries(realFilter).forEach( item => { if(item[1] === null) { - delete (realFilter as any)[item[0]]; + delete (realFilter as Object)[item[0] as keyof Object]; } }); const needReload = From 81c7e7710bac30871f4bc398c4a5d06fc34370d1 Mon Sep 17 00:00:00 2001 From: "troy.lty" Date: Thu, 31 Oct 2019 20:17:37 +0800 Subject: [PATCH 3/3] chore: add comments --- src/useAntdTable/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/useAntdTable/index.ts b/src/useAntdTable/index.ts index fe8a5390b6..ebcce6d9e8 100644 --- a/src/useAntdTable/index.ts +++ b/src/useAntdTable/index.ts @@ -347,13 +347,14 @@ function useAntdTable( f: Record = {} as Record, s: SorterResult = {} as SorterResult, ) => { - /* 如果 filter,或者 sort 变化,就初始化 current */ + // antd table 的初始状态 filter 带有 null 字段,需要先去除后再比较 const realFilter = {...f}; Object.entries(realFilter).forEach( item => { if(item[1] === null) { delete (realFilter as Object)[item[0] as keyof Object]; } }); + /* 如果 filter,或者 sort 变化,就初始化 current */ const needReload = !isEqual(realFilter, state.filters) || s.field !== state.sorter.field ||