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

feat(n-data-table): adds on-resize-start and on-resize event #6461

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- `n-progress`'s `color` prop supports gradient config.
- `n-select` adds `font-weight` theme variable
- `n-input` adds `font-weight` theme variable
- `n-data-table` adds `on-resize-start` and `on-resize` events, closes [#3827](https://github.com/tusen-ai/naive-ui/issues/3827)

## 2.40.1

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- `n-progress` 的 `color` 属性支持渐变色配置
- `n-select` 新增 `font-weight` 主题变量
- `n-input` 新增 `font-weight` 主题变量
- `n-data-table` 新增 `on-resize-start` 和 `on-resize` 事件,关闭 [#3827](https://github.com/tusen-ai/naive-ui/issues/3827)

## 2.40.1

Expand Down
2 changes: 2 additions & 0 deletions src/data-table/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export-csv.vue
| virtual-scroll-header | `boolean` | `false` | Whether to use virtual scrolling in table header. If there are too many columns, you can enable the prop. You must configure `header-height` at the same time. Enabling the prop will disable header cells that cross columns & rows. | 2.40.0 |
| virtual-scroll-x | `boolean` | `false` | Whether to use horizontal virtual scrolling in table body. If there are too many columns, you can enable the prop. Enabling the prop will disable body cells that cross columns & rows. If the prop is enabled, every column should have `width` prop configured and `virtual-scroll`, `scroll-x`, `min-row-height`, `height-for-row`, `virtual-scroll-header` (optional), `header-height` (optional) props should be configured at the same time. You can refer to <n-a href="#virtual-x.vue">the example</n-a>. | 2.40.0 |
| on-load | `(rowData: object) => Promise<void>` | `undefined` | Callback of async tree data expanding. | 2.27.0 |
| on-resize-start | `(column: DataTableBaseColumn) => void` | `undefined` | Callback triggered when column width dragging starts. | NEXT_VERSION |
| on-resize | `(column: DataTableBaseColumn, displacementX: number, startWidth: number) => void` | `undefined` | Callback triggered during column width dragging. | NEXT_VERSION |
| on-scroll | `(e: Event) => void` | `undefined` | Callback of table body scrolling. | 2.29.1 |
| on-update:checked-row-keys | `(keys: Array<string \| number>, rows: object[], meta: { row: object \| undefined, action: 'check' \| 'uncheck' \| 'checkAll' \| 'uncheckAll' }) => void` | `undefined` | The callback function triggered when the checked-row-keys value changes. | `rows` 2.30.5, `meta` 2.33.4 |
| on-update:expanded-row-keys | `(keys: Array<string \| number>) => void` | `undefined` | The callback function triggered when the expanded-row-keys value changes. | |
Expand Down
2 changes: 2 additions & 0 deletions src/data-table/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ rtl-debug.vue
| virtual-scroll-header | `boolean` | `false` | 是否打开表头的虚拟滚动,如果横向列太多,可以考虑打开此属性,打开此属性会导致表头单元格跨行列的功能不可用,同时必须要配置 `header-height` | 2.40.0 |
| virtual-scroll-x | `boolean` | `false` | 是否打开表主体的横向虚拟滚动,如果横向列太多,可以考虑打开此属性,打开此属性会导致单元格跨行列的功能不可用,此属性开启时,必须要和 `virtual-scroll`、`scroll-x`、`min-row-height`、`height-for-row`、`virtual-scroll-header`、`header-height` 属性配合使用,同时每一列必须都配置 `width` 属性,你可以参考 <n-a href="#virtual-x.vue">完整的例子</n-a> | 2.40.0 |
| on-load | `(rowData: object) => Promise<void>` | `undefined` | 异步展开树形数据的回调 | 2.27.0 |
| on-resize-start | `(column: DataTableBaseColumn) => void` | `undefined` | 列宽拖拽开始时触发的回调 | NEXT_VERSION |
| on-resize | `(column: DataTableBaseColumn, displacementX: number, startWidth: number) => void` | `undefined` | 列宽拖拽过程中触发的回调 | NEXT_VERSION |
| on-scroll | `(e: Event) => void` | `undefined` | 表格主体滚动的回调 | 2.29.1 |
| on-update:checked-row-keys | `(keys: Array<string \| number>, rows: object[], meta: { row: object \| undefined, action: 'check' \| 'uncheck' \| 'checkAll' \| 'uncheckAll' }) => void` | `undefined` | checked-row-keys 值改变时触发的回调函数 | `rows` 2.30.5, `meta` 2.33.4 |
| on-update:expanded-row-keys | `(keys: Array<string \| number>) => void` | `undefined` | expanded-row-keys 值改变时触发的回调函数 | |
Expand Down
4 changes: 3 additions & 1 deletion src/data-table/src/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ export default defineComponent({
handleTableHeaderScroll,
handleTableBodyScroll,
setHeaderScrollLeft,
renderCell: toRef(props, 'renderCell')
renderCell: toRef(props, 'renderCell'),
onResizeStart: props.onResizeStart,
onResize: props.onResize
})
const exposedMethods: DataTableInst = {
filter,
Expand Down
6 changes: 5 additions & 1 deletion src/data-table/src/TableParts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export default defineComponent({
handleTableHeaderScroll,
deriveNextSorter,
doUncheckAll,
doCheckAll
doCheckAll,
onResizeStart,
onResize
} = inject(dataTableInjectionKey)!
const virtualListRef = ref<VirtualListInst | null>()
const cellElsRef = ref<Record<ColumnKey, HTMLTableCellElement>>({})
Expand Down Expand Up @@ -141,13 +143,15 @@ export default defineComponent({
}
const resizeStartWidthMap = new Map<ColumnKey, number | undefined>()
function handleColumnResizeStart(column: TableBaseColumn): void {
onResizeStart?.(column)
resizeStartWidthMap.set(column.key, getCellActualWidth(column.key))
}
function handleColumnResize(
column: TableBaseColumn,
displacementX: number
): void {
const startWidth = resizeStartWidthMap.get(column.key)
onResize?.(column, displacementX, startWidth)
if (startWidth === undefined) {
return
}
Expand Down
12 changes: 12 additions & 0 deletions src/data-table/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export const dataTableProps = {
>,
onCheckedRowKeysChange: [Function, Array] as PropType<
MaybeArray<OnUpdateCheckedRowKeys> | undefined
>,
onResizeStart: Function as PropType<(column: TableBaseColumn) => void>,
onResize: Function as PropType<
(column: TableBaseColumn, displacementX: number) => void
>
} as const

Expand Down Expand Up @@ -447,6 +451,14 @@ export interface DataTableInjection {
| undefined
| ((value: any, rowData: object, column: TableBaseColumn) => VNodeChild)
>
onResizeStart: ((column: TableBaseColumn) => void) | undefined
onResize:
| ((
column: TableBaseColumn,
displacementX: number,
startWidth?: number
) => void)
| undefined
}

export const dataTableInjectionKey
Expand Down
Loading