-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(table): 将表格中的交互统一加上回调事件 (#2977) * feat(table): 排序与分页合并为onChange(#2977) * fix: 修改错误 * fix: 修改 * chore: 代码格式 --------- Co-authored-by: wanjinping <[email protected]>
- Loading branch information
Showing
7 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/table": minor | ||
--- | ||
|
||
feat: 将表格中的交互统一加上回调事件 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
feat(table): 将表格中的交互统一加上回调事件 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useEffect, useRef } from 'react' | ||
import { TableColumnItem, FlattedTableRowData } from '../types' | ||
|
||
export interface Sorter { | ||
order: string | null | ||
column: TableColumnItem | ||
} | ||
|
||
export interface Action { | ||
sorter?: Sorter | ||
} | ||
|
||
export interface Extra { | ||
action: keyof Action | ||
currentDataSource: object[] | ||
} | ||
|
||
export interface UseChangeProps { | ||
activeSorterColumn: string | null | ||
activeSorterType: string | null | ||
columns: TableColumnItem[] | ||
showData: FlattedTableRowData[] | ||
onChange?: (action: Action, extra: Extra) => void | ||
} | ||
|
||
export const useChange = ({ | ||
activeSorterColumn, | ||
activeSorterType, | ||
columns, | ||
showData, | ||
onChange, | ||
}: UseChangeProps) => { | ||
const changeRef = useRef({ | ||
sort: { activeSorterColumn, activeSorterType }, | ||
}) | ||
|
||
useEffect(() => { | ||
const { sort } = changeRef.current | ||
const sortNotChange = | ||
sort.activeSorterColumn === activeSorterColumn && sort.activeSorterType === activeSorterType | ||
if (sortNotChange) return | ||
const changeObj = { | ||
sorter: { | ||
order: activeSorterType, | ||
column: columns.filter((d) => d.dataKey === activeSorterColumn)[0], | ||
}, | ||
extra: { | ||
action: 'sorter', | ||
currentDataSource: showData.map((d) => d.raw), | ||
} as Extra, | ||
} | ||
onChange?.({ sorter: changeObj.sorter }, changeObj.extra) | ||
sort.activeSorterColumn = activeSorterColumn | ||
sort.activeSorterType = activeSorterType | ||
}, [activeSorterColumn, activeSorterType, columns, showData, onChange]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters