-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comp: table): support multiple sort (#917)
fix #915
- Loading branch information
Showing
13 changed files
with
261 additions
and
79 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
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,14 @@ | ||
--- | ||
title: | ||
zh: 多列排序 | ||
en: Multiple sort | ||
order: 42 | ||
--- | ||
|
||
## zh | ||
|
||
如果设置了 `sortable` 的 `multiple`,表格的排序将支持多列。 | ||
|
||
## en | ||
|
||
If `multiple` is set to `sortable`, sorting of tables will support multiple columns. |
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,132 @@ | ||
<template> | ||
<IxTable :columns="columns" :dataSource="data" :pagination="false"> | ||
<template #name="{ value }"> | ||
<a>{{ value }}</a> | ||
</template> | ||
</IxTable> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { reactive } from 'vue' | ||
import { TableColumn, TableColumnSortable } from '@idux/components/table' | ||
interface Data { | ||
key: number | ||
name: string | ||
age: number | ||
grade: number | ||
address: string | ||
} | ||
const ageSortable = reactive<TableColumnSortable<Data>>({ | ||
orderBy: 'ascend', | ||
sorter: (curr, next) => curr.age - next.age, | ||
onChange: currOrderBy => { | ||
ageSortable.orderBy = currOrderBy | ||
gradeSortable.orderBy = undefined | ||
}, | ||
}) | ||
const gradeSortable = reactive<TableColumnSortable<Data>>({ | ||
orders: ['ascend', 'descend', 'ascend'], | ||
sorter: (curr, next) => curr.grade - next.grade, | ||
onChange: currOrderBy => { | ||
ageSortable.orderBy = undefined | ||
gradeSortable.orderBy = currOrderBy | ||
}, | ||
}) | ||
const columns: TableColumn<Data>[] = [ | ||
{ | ||
title: 'Name', | ||
dataKey: 'name', | ||
sortable: { | ||
multiple: 1, | ||
orders: ['descend'], | ||
sorter: (curr, next) => curr.name.charCodeAt(0) - next.name.charCodeAt(0), | ||
}, | ||
customCell: 'name', | ||
}, | ||
{ | ||
title: 'Age', | ||
dataKey: 'age', | ||
sortable: { | ||
multiple: 2, | ||
sorter: (curr, next) => curr.age - next.age, | ||
}, | ||
}, | ||
{ | ||
title: 'Grade', | ||
dataKey: 'grade', | ||
sortable: { | ||
multiple: 3, | ||
orders: ['ascend', 'descend', 'ascend'], | ||
sorter: (curr, next) => curr.grade - next.grade, | ||
}, | ||
}, | ||
{ | ||
title: 'Address', | ||
dataKey: 'address', | ||
}, | ||
] | ||
const data: Data[] = [ | ||
{ | ||
key: 1, | ||
name: 'John Brown', | ||
age: 18, | ||
grade: 1, | ||
address: 'New York No. 1 Lake Park', | ||
}, | ||
{ | ||
key: 2, | ||
name: 'Jim Green', | ||
age: 20, | ||
grade: 3, | ||
address: 'London No. 1 Lake Park', | ||
}, | ||
{ | ||
key: 3, | ||
name: 'Joe Black', | ||
age: 19, | ||
grade: 2, | ||
address: 'Sidney No. 1 Lake Park', | ||
}, | ||
{ | ||
key: 4, | ||
name: 'Disabled User', | ||
age: 21, | ||
grade: 2, | ||
address: 'Sidney No. 1 Lake Park', | ||
}, | ||
{ | ||
key: 5, | ||
name: 'John Brown', | ||
age: 18, | ||
grade: 2, | ||
address: 'Sidney No. 1 Lake Park', | ||
}, | ||
{ | ||
key: 6, | ||
name: 'Jim Green', | ||
age: 20, | ||
grade: 1, | ||
address: 'London No. 1 Lake Park', | ||
}, | ||
{ | ||
key: 7, | ||
name: 'Joe Black', | ||
age: 19, | ||
grade: 1, | ||
address: 'Sidney No. 1 Lake Park', | ||
}, | ||
{ | ||
key: 8, | ||
name: 'Disabled User', | ||
age: 21, | ||
grade: 3, | ||
address: 'Sidney No. 1 Lake Park', | ||
}, | ||
] | ||
</script> |
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
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
Oops, something went wrong.