Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Table] 1. 筛选对话框输入筛选内容之后按回车应该和按确定按钮一样;2. 筛选功能支持自定义组件方式 #952

Merged
merged 23 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
49072ba
docs(notification): 插件调用与函数式调用
Feb 11, 2022
8e5badf
Merge remote-tracking branch 'upstream/develop' into develop
Feb 14, 2022
5d3dd2a
Merge remote-tracking branch 'upstream/develop' into develop
Feb 15, 2022
df1f39a
Merge remote-tracking branch 'upstream/develop' into develop
chaishi Mar 23, 2022
e9a6f2e
Merge remote-tracking branch 'upstream/develop' into develop
chaishi Mar 28, 2022
993a2a4
Merge remote-tracking branch 'upstream/develop' into develop
chaishi Mar 29, 2022
bbe4c10
fix(table): merged cells border style
chaishi Mar 29, 2022
51a9b4b
feat: merge from upstream/develop
chaishi Mar 31, 2022
93a15e0
Merge remote-tracking branch 'upstream/develop' into develop
chaishi Apr 21, 2022
e57dd2d
Merge remote-tracking branch 'upstream/develop' into develop
chaishi Apr 25, 2022
36d3778
Merge remote-tracking branch 'upstream/develop' into develop
chaishi Apr 30, 2022
1db46ab
Merge remote-tracking branch 'upstream/develop' into develop
chaishi May 10, 2022
edd9e3b
Merge remote-tracking branch 'upstream/develop' into develop
chaishi May 10, 2022
9b4b001
Merge remote-tracking branch 'upstream/develop' into develop
chaishi May 13, 2022
267b4ea
Merge remote-tracking branch 'upstream/develop' into develop
chaishi May 16, 2022
95996fe
Merge remote-tracking branch 'upstream/develop' into develop
chaishi May 21, 2022
871f1b1
fix(table): toggleData and FoldAll
chaishi May 21, 2022
f5bb2e9
fix(table): 树形结构中,动态设置行选中列时,禁用功能失效
chaishi May 21, 2022
d310f05
Merge remote-tracking branch 'upstream/develop' into develop
chaishi May 29, 2022
7456a08
Merge remote-tracking branch 'upstream/develop' into develop
chaishi Jun 4, 2022
046c641
feat(table): support filter.confirmEvents and custom filter component
chaishi Jun 4, 2022
02bc54c
feat(table): rename allowResizeColumnWidth to resizable; add column.r…
chaishi Jun 4, 2022
12c63e4
docs(table): update affix documents
chaishi Jun 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/table/demos/affix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:footerAffixProps="{ offsetBottom: 0, zIndex: 1000 }"
tableLayout="auto"
bordered
allowResizeColumnWidth
resizable
>
<template #t-foot-required> 插槽渲染表尾 </template>
</t-table>
Expand Down
1 change: 1 addition & 0 deletions examples/table/demos/base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
:size="size"
:table-layout="tableLayout ? 'auto' : 'fixed'"
:pagination="pagination"
resizable
></t-table>
</div>
</template>
Expand Down
14 changes: 13 additions & 1 deletion examples/table/demos/filter-controlled.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@
:data="data"
:filter-value="filterValue"
:bordered="bordered"
resizable
@filter-change="onFilterChange"
@change="onChange"
/>
</div>
</template>

<script lang="jsx">
import { DatePicker } from 'tdesign-vue';

const data = new Array(5).fill(null).map((_, i) => ({
key: String(i + 1),
firstName: ['Eric', 'Gilberta', 'Heriberto', 'Lazarus', 'Zandra'][i % 4],
Expand Down Expand Up @@ -108,6 +111,8 @@ export default {
filter: {
type: 'input',
resetValue: '@',
// 按下 Enter 键时也触发确认搜索
confirmEvents: ['onEnter'],
props: {
placeholder: '输入关键词过滤',
clearable: true,
Expand All @@ -121,8 +126,15 @@ export default {
colKey: 'createTime',
// 自定义过滤组件:日期过滤配置,请确保自定义组件包含 value 和 onChange 属性
filter: {
// this config is not recommended.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
component: (h) => <t-date-picker clearable />,
// component: (h) => <t-date-picker clearable />,

// this config will be better.
component: DatePicker,
props: {
clearable: true,
},
},
},
];
Expand Down
2 changes: 1 addition & 1 deletion examples/table/demos/fixed-header-col.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
:scroll="virtualScroll ? { type: 'virtual' } : undefined"
:stripe="stripe"
bordered
allowResizeColumnWidth
resizable
>
<template #operation="slotProps">
<a class="link" @click="rehandleClickOp(slotProps)">删除</a>
Expand Down
13 changes: 8 additions & 5 deletions examples/table/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
allowResizeColumnWidth | Boolean | false | 是否允许调整列宽 | N
allowResizeColumnWidth | Boolean | undefined | 已废弃。是否允许调整列宽。请更为使用 `resizable` | N
bordered | Boolean | false | 是否显示表格边框 | N
bottomContent | String / Slot / Function | - | 表格底部内容,可以用于自定义列设置等。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
columns | Array | [] | 列配置,泛型 T 指表格数据类型。TS 类型:`Array<BaseTableCol<T>>` | N
Expand All @@ -15,9 +15,9 @@ empty | String / Slot / Function | '' | 空表格呈现样式,支持全局配
firstFullRow | String / Slot / Function | - | 首行内容。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
fixedRows | Array | - | 固定行(冻结行),示例:[M, N],表示冻结表头 M 行和表尾 N 行。M 和 N 值为 0 时,表示不冻结行。TS 类型:`Array<number>` | N
footData | Array | [] | 表尾数据源,泛型 T 指表格数据类型。TS 类型:`Array<T>` | N
footerAffixedBottom | Boolean | false | 表尾吸底 | N
footerAffixedBottom | Boolean | false | 表尾吸底。使用此向功能,需要非常注意表格是相对于哪一个父元素进行滚动,默认为整个窗口。如果表格滚动的父元素不是整个窗口,请通过 `footerAffixProps.container` 调整固钉的吸顶范围 | N
footerAffixProps | Object | - | 表尾吸底基于 Affix 组件开发,透传全部 Affix 组件属性。TS 类型:`AffixProps` | N
headerAffixedTop | Boolean | false | 表头吸顶 | N
headerAffixedTop | Boolean | false | 表头吸顶。使用此向功能,需要非常注意表格是相对于哪一个父元素进行滚动,默认为整个窗口。如果表格滚动的父元素不是整个窗口,请通过 `headerAffixProps.container` 调整固钉的吸顶范围 | N
headerAffixProps | Object | - | 表头吸顶基于 Affix 组件开发,透传全部 Affix 组件属性。TS 类型:`AffixProps`,[Affix API Documents](./affix?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
height | String / Number | - | 表格高度,超出后会出现滚动条。示例:100, '30%', '300'。值为数字类型,会自动加上单位 px。如果不是绝对固定表格高度,建议使用 `maxHeight` | N
hover | Boolean | false | 是否显示鼠标悬浮状态 | N
Expand All @@ -26,6 +26,7 @@ loading | Boolean / Slot / Function | undefined | 加载中状态。值为 `true
loadingProps | Object | - | 透传加载组件全部属性。TS 类型:`LoadingProps`,[Loading API Documents](./loading?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
maxHeight | String / Number | - | 表格最大高度,超出后会出现滚动条。示例:100, '30%', '300'。值为数字类型,会自动加上单位 px | N
pagination | Object | - | 分页配置,值为空则不显示。具体 API 参考分页组件。当 `data` 数据长度超过分页大小时,会自动对本地数据 `data` 进行排序,如果不希望对于 `data` 进行排序,可以设置 `disableDataPage = true`。TS 类型:`PaginationProps`,[Pagination API Documents](./pagination?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
resizable | Boolean | false | 是否允许调整列宽。如果想要配置宽度可调整的最小值和最大值,请使用 `column.resize`,示例:`columns: [{ resize: { minWidth: 120, maxWidth: 300 } }]` | N
rowAttributes | Object / Array / Function | - | HTML 标签 `tr` 的属性。类型为 Function 时,参数说明:`params.row` 表示行数据;`params.rowIndex` 表示行下标;`params.type=body` 表示属性作用于 `tbody` 中的元素;`params.type=foot` 表示属性作用于 `tfoot` 中的元素。<br />示例一:{ draggable: true },<br />示例二:[{ draggable: true }, { title: '超出省略显示' }]。<br /> 示例三:() => [{ draggable: true }]。TS 类型:`TableRowAttributes<T>` `type TableRowAttributes<T> = HTMLElementAttributes | ((params: { row: T; rowIndex: number; type: 'body' | 'foot' }) => HTMLElementAttributes) | Array<TableRowAttributes<T>>`。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
rowClassName | String / Object / Array / Function | - | 行类名,泛型 T 指表格数据类型。`params.row` 表示行数据;`params.rowIndex` 表示行下标;`params.type=body` 表示类名作用于 `tbody` 中的元素;`params.type=body` 表示类名作用于 `tfoot` 中的元素。TS 类型:`ClassName | ((params: RowClassNameParams<T>) => ClassName)` `interface RowClassNameParams<T> { row: T; rowIndex: number; type?: 'body' | 'foot' }`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
rowKey | String | 'id' | 必需。使用 rowKey 唯一标识一行数据 | Y
Expand Down Expand Up @@ -82,6 +83,7 @@ ellipsisTitle | Boolean / Object / Slot / Function | undefined | 表头内容超
fixed | String | left | 固定列显示位置。可选项:left/right | N
foot | String / Function | - | 自定义表尾表尾。值类型为 Function 表示以函数形式渲染表尾内容。值类型为 string 表示使用插槽渲染,插槽名称为 `foot` 值。TS 类型:`string | TNode<{ col: BaseTableCol; colIndex: number }>`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
render | Function | - | 自定义表头或单元格,泛型 T 指表格数据类型。TS 类型:`TNode<BaseTableRenderParams<T>>` `interface BaseTableRenderParams<T> extends BaseTableCellParams<T> { type: RenderType }` `type RenderType = 'cell' | 'title'`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
resize | Object | - | 限制拖拽调整的最小宽度和最大宽度。`resize.minWidth` 默认为 `80`,`resize.maxWidth` 默认为 `600`。TS 类型:`TableColumnResizeConfig` `interface TableColumnResizeConfig { minWidth: number; maxWidth: number }`。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
title | String / Function | - | 自定义表头渲染。值类型为 Function 表示以函数形式渲染表头。值类型为 string 表示使用插槽渲染,插槽名称为 title 的值。优先级高于 render。TS 类型:`string | TNode<{ col: BaseTableCol; colIndex: number }>`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
width | String / Number | - | 列宽,可以作为最小宽度使用。当列宽总和小于 `table` 元素时,浏览器根据宽度设置情况自动分配宽度;当列宽总和大于 `table` 元素,表现为定宽。可以同时调整 `table` 元素的宽度来达到自己想要的效果 | N

Expand Down Expand Up @@ -156,7 +158,7 @@ children | Array | - | 用于多级表头,泛型 T 指表格数据类型。TS
colKey | String | - | 渲染列所需字段,必须唯一。值为 `row-select` 表示当前列为行选中操作列。值为 `drag` 表示当前列为拖拽排序操作列 | N
disabled | Function | - | 是否禁用行选中,`colKey` 值为 `row-select` 时,配置有效。TS 类型:`(options: {row: T; rowIndex: number }) => boolean` | N
edit | Object | - | 可编辑单元格配置项,具体属性参考文档 `TableEditableCellConfig` 描述。TS 类型:`TableEditableCellConfig<T>` | N
filter | Object | - | 过滤规则,支持多选(multiple)、单选(single)、输入框(input) 等三种形式。想要自定义过滤组件,可通过 `filter.component` 实现,自定义过滤组件需要包含参数 value 和事件 change。TS 类型:`TableColumnFilter` | N
filter | Object | - | 过滤规则,支持多选(multiple)、单选(single)、输入框(input) 等三种形式。想要自定义过滤组件,可通过 `filter.component` 实现,自定义过滤组件需要包含参数 value 和事件 change。更多信息请查看当前页面中 `TableColumnFilter` 的详细文档。TS 类型:`TableColumnFilter` | N
render | Function | - | 自定义表头或单元格,泛型 T 指表格数据类型。TS 类型:`TNode<PrimaryTableRenderParams<T>>` `interface PrimaryTableRenderParams<T> extends PrimaryTableCellParams<T> { type: RenderType }`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
sorter | Boolean / Function | false | 该列是否支持排序。值为 true 表示该列支持排序;值类型为函数,表示对本地数据 `data` 进行排序,返回值参考 [MDN Array.sort](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)。泛型 T 指表格数据类型。TS 类型:`boolean | SorterFun<T>` `type SorterFun<T> = (a: T, b: T) => number`。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
sortType | String | all | 当前列支持排序的方式,desc 表示当前列只能进行降序排列;asc 表示当前列只能进行升序排列;all 表示当前列既可升序排列,又可以降序排列。可选项:desc/asc/all。TS 类型:`SortType` `type SortType = 'desc' | 'asc' | 'all'`。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
Expand Down Expand Up @@ -216,7 +218,8 @@ rowIndex | Number | - | 必需。表格行下标,值为 `-1` 标识当前行

名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
component | Slot / Function | - | 用于自定义筛选器,只要保证自定义筛选器包含 value 属性 和 change 事件,即可像内置筛选器一样正常使用。TS 类型:`TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
component | Slot / Function | - | 用于自定义筛选器,只要保证自定义筛选器包含 value 属性 和 change 事件,即可像内置筛选器一样正常使用。示例:`component: DatePicker`。TS 类型:`ComponentType`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
confirmEvents | Array | - | 哪些事件触发后会进行过滤搜索(确认按钮无需配置,会默认触发搜索)。输入框组件示例:`confirmEvents: ['onEnter']`。TS 类型:`string[]` | N
list | Array | - | 用于配置当前筛选器可选值有哪些,仅当 `filter.type` 等于 `single` 或 `multiple` 时有效。TS 类型:`Array<OptionData>`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
props | Array | - | 用于透传筛选器属性,可以对筛选器进行任何原组件支持的属性配置。TS 类型:`FilterProps` `type FilterProps = RadioProps | CheckboxProps | InputProps | { [key: string]: any }`,[Input API Documents](./input?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts) | N
resetValue | \- | - | 重置时设置的值,示例:'' 或 []。TS 类型:`any` | N
Expand Down
13 changes: 9 additions & 4 deletions src/table/base-table-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { TdBaseTableProps } from '../table/type';
import { PropType } from 'vue';

export default {
/** 是否允许调整列宽 */
allowResizeColumnWidth: Boolean,
/** 已废弃。是否允许调整列宽。请更为使用 `resizable` */
allowResizeColumnWidth: {
type: Boolean,
default: undefined,
},
/** 是否显示表格边框 */
bordered: Boolean,
/** 表格底部内容,可以用于自定义列设置等 */
Expand Down Expand Up @@ -46,13 +49,13 @@ export default {
type: Array as PropType<TdBaseTableProps['footData']>,
default: (): TdBaseTableProps['footData'] => [],
},
/** 表尾吸底 */
/** 表尾吸底。使用此向功能,需要非常注意表格是相对于哪一个父元素进行滚动,默认为整个窗口。如果表格滚动的父元素不是整个窗口,请通过 `footerAffixProps.container` 调整固钉的吸顶范围 */
footerAffixedBottom: Boolean,
/** 表尾吸底基于 Affix 组件开发,透传全部 Affix 组件属性 */
footerAffixProps: {
type: Object as PropType<TdBaseTableProps['footerAffixProps']>,
},
/** 表头吸顶 */
/** 表头吸顶。使用此向功能,需要非常注意表格是相对于哪一个父元素进行滚动,默认为整个窗口。如果表格滚动的父元素不是整个窗口,请通过 `headerAffixProps.container` 调整固钉的吸顶范围 */
headerAffixedTop: Boolean,
/** 表头吸顶基于 Affix 组件开发,透传全部 Affix 组件属性 */
headerAffixProps: {
Expand Down Expand Up @@ -85,6 +88,8 @@ export default {
pagination: {
type: Object as PropType<TdBaseTableProps['pagination']>,
},
/** 是否允许调整列宽。如果想要配置宽度可调整的最小值和最大值,请使用 `column.resize`,示例:`columns: [{ resize: { minWidth: 120, maxWidth: 300 } }]` */
resizable: Boolean,
/** HTML 标签 `tr` 的属性。类型为 Function 时,参数说明:`params.row` 表示行数据;`params.rowIndex` 表示行下标;`params.type=body` 表示属性作用于 `tbody` 中的元素;`params.type=foot` 表示属性作用于 `tfoot` 中的元素。<br />示例一:{ draggable: true },<br />示例二:[{ draggable: true }, { title: '超出省略显示' }]。<br /> 示例三:() => [{ draggable: true }] */
rowAttributes: {
type: [Object, Array, Function] as PropType<TdBaseTableProps['rowAttributes']>,
Expand Down
9 changes: 7 additions & 2 deletions src/table/base-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Affix } from '../affix';
import { ROW_LISTENERS } from './tr';
import THead from './thead';
import TFoot from './tfoot';
import log from '../_common/js/log';

export const BASE_TABLE_EVENTS = ['page-change', 'cell-click', 'scroll', 'scrollX', 'scrollY'];
export const BASE_TABLE_ALL_EVENTS = ROW_LISTENERS.map((t) => `row-${t}`).concat(BASE_TABLE_EVENTS);
Expand Down Expand Up @@ -238,6 +239,10 @@ export default defineComponent({
const { rowAndColFixedPosition } = this;
const data = this.isPaginateData ? this.dataSource : this.data;

if (this.allowResizeColumnWidth) {
log.warn('Table', 'allowResizeColumnWidth is going to be deprecated, please use resizable instead.');
}
const columnResizable = this.allowResizeColumnWidth === undefined ? this.resizable : this.allowResizeColumnWidth;
const defaultColWidth = this.tableLayout === 'fixed' && this.isWidthOverflow ? '100px' : undefined;
const colgroup = (
<colgroup>
Expand All @@ -263,7 +268,7 @@ export default defineComponent({
spansAndLeafNodes={this.spansAndLeafNodes}
thList={this.thList}
thWidthList={this.thWidthList}
allowResizeColumnWidth={this.allowResizeColumnWidth}
resizable={columnResizable}
columnResizeParams={this.columnResizeParams}
/>
</table>
Expand Down Expand Up @@ -356,7 +361,7 @@ export default defineComponent({
bordered={this.bordered}
spansAndLeafNodes={this.spansAndLeafNodes}
thList={this.thList}
allowResizeColumnWidth={this.allowResizeColumnWidth}
resizable={columnResizable}
columnResizeParams={this.columnResizeParams}
/>
<TBody scopedSlots={this.$scopedSlots} props={tableBodyProps} on={on} />
Expand Down
Loading