@@ -71,7 +71,7 @@ function WrappedTable<T extends object = any>({
71
71
const sortCompareRef = React . useRef < ( ( a : T , b : T ) => number ) | null > ( null ) ;
72
72
const [ defaultPagination , setDefaultPagination ] = React . useState < TablePaginationConfig > ( {
73
73
current : 1 ,
74
- total : dataSource . length ,
74
+ total : dataSource ? .length || 0 ,
75
75
...PAGINATION ,
76
76
} ) ;
77
77
const isFrontendPaging = ! ( paginationProps && paginationProps . current ) && paginationProps !== false ; // Determine whether front-end paging
@@ -82,7 +82,7 @@ function WrappedTable<T extends object = any>({
82
82
const { current = 1 , pageSize = PAGINATION . pageSize } = pagination ;
83
83
84
84
React . useEffect ( ( ) => {
85
- setDefaultPagination ( ( before ) => ( { ...before , current : 1 , total : dataSource . length } ) ) ;
85
+ setDefaultPagination ( ( before ) => ( { ...before , current : 1 , total : dataSource ? .length || 0 } ) ) ;
86
86
} , [ dataSource ] ) ;
87
87
88
88
const onTableChange = React . useCallback (
@@ -136,7 +136,7 @@ function WrappedTable<T extends object = any>({
136
136
const onSort = ( order ?: 'ascend' | 'descend' ) => {
137
137
setSort ( { ...sorter , order } ) ;
138
138
const { sorter : columnSorter } = column as { sorter : { compare : ( a : T , b : T ) => number } } ;
139
- if ( columnSorter ?. compare ) {
139
+ if ( order && columnSorter ?. compare ) {
140
140
sortCompareRef . current = ( a : T , b : T ) => {
141
141
if ( order === 'ascend' ) {
142
142
return columnSorter ?. compare ?.( a , b ) ;
@@ -250,7 +250,7 @@ function WrappedTable<T extends object = any>({
250
250
) ;
251
251
} , [ allColumns , sorterMenu , sort , onRow ] ) ;
252
252
253
- let data = [ ...dataSource ] as T [ ] ;
253
+ let data : T [ ] = dataSource ? [ ...dataSource ] : [ ] ;
254
254
255
255
if ( sortCompareRef . current ) {
256
256
data = data . sort ( sortCompareRef . current ) ;
0 commit comments