Skip to content

Commit

Permalink
feat(Table): 增加 afterSort 事件 (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
1zumii authored Apr 18, 2024
1 parent 40dbf37 commit 097f37b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default defineComponent({
'selectAll',
'selectionChange',
'sortChange',
'afterSort',
'dragstart',
'dragend',
'update:checkedKeys',
Expand Down
10 changes: 7 additions & 3 deletions components/table/useTableSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default ({

const handleRowDataBySort = (data: RowType[], param: SortStateType) => {
const { prop, order, sorter } = param;

let nextData = data;
if (order === 'ascend') {
return data.sort((a: RowType, b: RowType) => {
nextData = data.sort((a: RowType, b: RowType) => {
let res = 0;
if (typeof sorter === 'function') {
try {
Expand All @@ -34,7 +36,7 @@ export default ({
});
}
if (order === 'descend') {
return data.sort((a: RowType, b: RowType) => {
nextData = data.sort((a: RowType, b: RowType) => {
let res = 0;
if (typeof sorter === 'function') {
try {
Expand All @@ -47,7 +49,9 @@ export default ({
return res;
});
}
return data;

ctx.emit('afterSort', readonly(nextData));
return nextData;
};

const handleClickSortHeader = ({ column }: { column: ColumnInst }) => {
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/components/table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ resizable.vue
| dragstart | 拖拽开始触发 | (event, item, index) => void |
| dragend | 拖拽结束触发 | (event, item, index) => void |
| sortChange | 点击排序后触发 | ({prop?: string; order?: 'descend' \| 'ascend'; sorter?: Function \| 'default'}) => void |
| afterSort | 排序完成后触发 | (data) => void |

## FTable Methods

Expand Down

0 comments on commit 097f37b

Please sign in to comment.