Skip to content

Commit

Permalink
feat(comp:table): redesign TableColumn and support children in templa…
Browse files Browse the repository at this point in the history
…te (#708)

BREAKING CHANGE: `customRender`, `customTtile`, `customIcon` and `customExpand` have been
deprecated, please use `slots` instead
  • Loading branch information
danranVm committed Jan 7, 2022
1 parent 526c71e commit 356faaf
Show file tree
Hide file tree
Showing 37 changed files with 529 additions and 516 deletions.
24 changes: 13 additions & 11 deletions packages/components/table/demo/Basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script lang="ts" setup>
import { h } from 'vue'
import { TableColumn, TableColumnRenderOption } from '@idux/components/table'
import { TableColumn } from '@idux/components/table'
import { IxTag } from '@idux/components/tag'
interface Data {
Expand All @@ -28,7 +28,7 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand All @@ -41,19 +41,21 @@ const columns: TableColumn<Data>[] = [
{
title: 'Tags',
dataKey: 'tags',
customRender: ({ value }: TableColumnRenderOption<Data['tags'], Data>) =>
value.map(tag => {
let color = tag.length > 5 ? 'warning' : 'success'
if (tag === 'loser') {
color = 'error'
}
return h(IxTag, { color }, { default: () => tag.toUpperCase() })
}),
slots: {
cell: ({ value }) =>
value.map((tag: string) => {
let color = tag.length > 5 ? 'warning' : 'success'
if (tag === 'loser') {
color = 'error'
}
return h(IxTag, { color }, { default: () => tag.toUpperCase() })
}),
},
},
{
title: 'Action',
key: 'action',
customRender: 'action',
slots: { cell: 'action' },
},
]
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/demo/ColSpanRowSpan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
colSpan: record => (record.name === 'Jake White' ? 5 : 1),
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down
4 changes: 2 additions & 2 deletions packages/components/table/demo/Expandable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const columns: TableColumn<Data>[] = [
type: 'expandable',
disabled: record => !record.description,
onChange: expendedRowKeys => console.log(expendedRowKeys),
customExpand: 'expand',
slots: { expand: 'expand' },
},
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down
10 changes: 4 additions & 6 deletions packages/components/table/demo/Filterable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ interface Data {
address: string
}
type AgeFilter = (age: number) => boolean
const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand All @@ -46,7 +44,7 @@ const columns: TableColumn<Data>[] = [
return currentFilterBy.every(filterBy => filterBy(record.age))
},
},
} as TableColumn<Data, AgeFilter>,
},
{
title: 'Grade',
dataKey: 'grade',
Expand All @@ -65,11 +63,11 @@ const columns: TableColumn<Data>[] = [
value: 'New York',
},
],
handleFilter(currentFilterBy, record) {
filter(currentFilterBy, record) {
return currentFilterBy.every(filterBy => record.address.includes(filterBy))
},
},
} as TableColumn<Data, string>,
},
]
const data: Data[] = [
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/demo/FilterableFilterBy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down
4 changes: 2 additions & 2 deletions packages/components/table/demo/Fixed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
width: 100,
fixed: 'start',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down Expand Up @@ -85,7 +85,7 @@ const columns: TableColumn<Data>[] = [
key: 'action',
fixed: 'end',
width: 100,
customRender: 'action',
slots: { cell: 'action' },
},
]
Expand Down
6 changes: 1 addition & 5 deletions packages/components/table/demo/HeadGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
<template #name="{ value }">
<a>{{ value }}</a>
</template>
<template #action="{ record }">
<a style="margin-right: 8px">Invite {{ record.name }}</a>
<a>Delete</a>
</template>
</IxTable>
</template>

Expand All @@ -29,9 +25,9 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
width: 100,
fixed: 'start',
slots: { cell: 'name' },
},
{
title: 'Other',
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/demo/Selectable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down
20 changes: 11 additions & 9 deletions packages/components/table/demo/SelectableOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script lang="ts" setup>
import { ref } from 'vue'
import { VKey } from '@idux/cdk/utils'
import { TableColumn } from '@idux/components/table'
interface Data {
Expand All @@ -18,38 +19,39 @@ interface Data {
address: string
}
const selectedRowKeys = ref<(string | number)[]>([])
const selectedRowKeys = ref<VKey[]>([])
const columns: TableColumn<Data>[] = [
{
type: 'selectable',
disabled: record => record.key % 10 === 9,
options: [
menus: [
'all',
'invert',
'none',
'pageInvert',
{
type: 'item',
key: 'odd',
label: 'Select Odd Row',
onClick: currentPageRowKeys => {
selectedRowKeys.value = currentPageRowKeys.filter((_, index) => index % 2 === 0)
},
},
{
type: 'item',
key: 'even',
label: 'Select Even Row',
onClick: currentPageRowKeys => {
selectedRowKeys.value = currentPageRowKeys.filter((_, index) => index % 2 !== 0)
},
},
],
onChange: (selectedKeys, selectedRows) => console.log(selectedKeys, selectedRows),
onMenuClick: (options, currentPageRowKeys) => {
const filterFlag = options.key === 'odd' ? 0 : 1
selectedRowKeys.value = currentPageRowKeys.filter((_, index) => index % 2 === filterFlag)
},
},
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down
3 changes: 0 additions & 3 deletions packages/components/table/demo/Server.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<template>
<IxTable :columns="columns" :dataSource="dataSource" :rowKey="getRowKey" :pagination="pagination" :spin="loading">
<template #name="{ value }">
<a>{{ value }}</a>
</template>
</IxTable>
</template>

Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/demo/Sortable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
sortable: {
orders: ['descend'],
sorter: (curr, next) => curr.name.length - next.name.length,
},
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/demo/SortableOrderBy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down
25 changes: 14 additions & 11 deletions packages/components/table/demo/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script lang="ts" setup>
import { h } from 'vue'
import { TableColumn, TableColumnRenderOption } from '@idux/components/table'
import { TableColumn } from '@idux/components/table'
import { IxTag } from '@idux/components/tag'
interface Data {
Expand All @@ -35,7 +35,7 @@ const columns: TableColumn<Data>[] = [
indent: 10,
title: 'Event Name',
dataKey: 'eventName',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Description',
Expand All @@ -52,14 +52,17 @@ const columns: TableColumn<Data>[] = [
{
title: 'Tags',
dataKey: 'tags',
customRender: ({ value }: TableColumnRenderOption<Data['tags'], Data>) =>
value.map(tag => {
let color = tag.length > 5 ? 'warning' : 'success'
if (tag === 'attack' || tag === 'damage') {
color = 'error'
}
return h(IxTag, { color }, { default: () => tag.toUpperCase() })
}),
slots: {
cell: ({ value }) =>
value.map((tag: string) => {
let color = tag.length > 5 ? 'warning' : 'success'
if (tag === 'attack' || tag === 'damage') {
color = 'error'
}
return h(IxTag, { color }, { default: () => tag.toUpperCase() })
}),
},
filterable: {
filters: [
{
Expand All @@ -83,7 +86,7 @@ const columns: TableColumn<Data>[] = [
{
title: 'Action',
key: 'action',
customRender: 'action',
slots: { cell: 'action' },
},
]
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/demo/Virtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customRender: 'name',
slots: { cell: 'name' },
},
{
title: 'Age',
Expand Down

0 comments on commit 356faaf

Please sign in to comment.