diff --git a/packages/components/src/components/table/Table.tsx b/packages/components/src/components/table/Table.tsx index 41d46a9859..2a9d3f2090 100644 --- a/packages/components/src/components/table/Table.tsx +++ b/packages/components/src/components/table/Table.tsx @@ -1,5 +1,5 @@ /* eslint-disable no-param-reassign */ -import React, { useContext, useEffect, useMemo } from 'react'; +import React, { useContext, useMemo } from 'react'; import RcTable from 'rc-table'; import classNames from 'classnames'; import { cloneDeep, isUndefined, get, has, join } from 'lodash'; @@ -58,16 +58,17 @@ const Table = (props: TableProps): React.ReactElement = resetPagination, ] = usePagination(filtedData, pagination, showIndex); - useEffect(() => { - resetPagination(); - }, [dataSource]); - const [transformSelectionPipeline] = useSelection(paginationedData, rowSelection, { rowKey, }); const [transformEllipsisTooltipPipeline] = useEllipsisTooltip(); - const onTriggerStateUpdate = () => onChange?.(activePaginationedState, activeSorterStates, activeFilterStates); + const onTriggerStateUpdate = (reset: boolean = false) => { + if (reset) { + resetPagination(); + } + onChange?.(activePaginationedState, activeSorterStates, activeFilterStates); + }; const renderTitle = (_columns: ColumnsType) => _columns.map((column) => { diff --git a/packages/components/src/components/table/Title.tsx b/packages/components/src/components/table/Title.tsx index ea7aeb72ff..8e2d2c7337 100644 --- a/packages/components/src/components/table/Title.tsx +++ b/packages/components/src/components/table/Title.tsx @@ -1,17 +1,16 @@ import React from 'react'; import classNames from 'classnames'; -import { - UpFilled, DownFilled, FilterFilled, QuestionCircleOutlined, -} from '@gio-design/icons'; +import { UpFilled, DownFilled, FilterFilled, QuestionCircleOutlined } from '@gio-design/icons'; import { isUndefined } from 'lodash'; import Button from '../button'; import Tooltip from '../tooltip'; import FilterPopover from './FilterPopover'; import { SortOrder, TitleProps } from './interface'; -const getNextSortDirection = (sortDirections: SortOrder[], current: SortOrder): SortOrder => (current === null ? sortDirections[0] : sortDirections[sortDirections.indexOf(current) + 1]); +const getNextSortDirection = (sortDirections: SortOrder[], current: SortOrder): SortOrder => + current === null ? sortDirections[0] : sortDirections[sortDirections.indexOf(current) + 1]; -const Title = (props: TitleProps) => { +const Title = (props: TitleProps) => { const { prefixCls, column, onTriggerStateUpdate } = props; const renderSorter = () => { @@ -36,7 +35,7 @@ const Title = (props: TitleProps) => { prefixCls={`${prefixCls}`} className={`${prefixCls}-column-sorter-inner-btn`} type="text" - icon={( + icon={ <> (props: TitleProps) => { })} /> - )} + } onClick={handleSorterChange} /> @@ -65,7 +64,7 @@ const Title = (props: TitleProps) => { const { filteredKeys, filters } = filterState; const handleFilterPopoverClick = (newFilteredKeys: string[]) => { updateFilterStates({ ...filterState, filteredKeys: newFilteredKeys }); - onTriggerStateUpdate(); + onTriggerStateUpdate(true); }; return ( @@ -75,12 +74,12 @@ const Title = (props: TitleProps) => {