Skip to content

Commit

Permalink
feat(pro:table): support scrollTo
Browse files Browse the repository at this point in the history
disabled columns should not be changed when check all
  • Loading branch information
danranVm committed Aug 30, 2022
1 parent 9e65136 commit cde82e6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"@types/lodash-es": "^4.17.6",
"@types/marked": "^4.0.3",
"@types/node": "^17.0.45",
"@types/parse5": "^7.0.0",
"@types/prismjs": "^1.26.0",
"@types/svgo": "^2.6.3",
"@types/yaml-front-matter": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cdk/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare module 'vue' {
}

export interface GlobalDirectives {
VClickOutside: ClickOutsideDirective
vClickOutside: ClickOutsideDirective
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/components/table/docs/Api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export type TableColumn<T = any, V = any> =
| `onChange` | 选中状态发生变化时触发 | `(selectedRowKeys: (string \| number)[], selectedRecords: T[]) => void` | - | - | - |
| `onMenuClick` | 点击下拉菜单时触发 | `(options: MenuClickOptions, currentPageRowKeys: VKey[]) => void` | - | - | 如果点击时预设的值, 则不会触发该回调(例如:`all`, 那么触发的是 `onSelectAll`) |
| `onSelect` | 点击选择框,或通过 `trigger` 触发 | `(selected: boolean, record: T) => void` | - | - | - |
| `onSelectAll` | 点击全选所有时触发 | `(selectedRowKeys: (string \| number)[]) => void` | - | - | - |
| `onSelectInvert` | 点击反选所有时触发 | `(selectedRowKeys: (string \| number)[]) => void` | - | - | - |
| `onSelectNone` | 点击清空所有时触发 | `() => void` | - | - | - |
| `onSelectPageInvert` | 点击反选当页所有时触发 | `() => void` | - | - | - |
| `onSelectAll` | 点击全选所有时触发 | `(selectedRowKeys: (string \| number)[]) => void` | - | - | 配置 `menus= ['all']` 时生效 |
| `onSelectInvert` | 点击反选所有时触发 | `(selectedRowKeys: (string \| number)[]) => void` | - | - | 配置 `menus= ['invert']` 时生效 |
| `onSelectNone` | 点击清空所有时触发 | `() => void` | - | - | 配置 `menus= ['none']` 时生效 |
| `onSelectPageInvert` | 点击反选当页所有时触发 | `() => void` | - | - | 配置 `menus= ['pageInvert']` 时生效 |
##### TableColumnSortable
Expand Down
6 changes: 5 additions & 1 deletion packages/pro/table/docs/Api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ export const defaultConfig: ProGlobalConfig = {

### IxProTableLayoutTool

表格布局设置组件,通常在自定义 `header` 的时候设置它, 参见 [自定义头部](#pro-table-demo-CustomHeader).
表格布局设置组件,大部分情况下,你都不需要使用它。

只有当你设置了 `layoutTool='false'` 时,并需要在表格的其他位置来控制表格的布局时使用。

例如: 在自定义 `header` 的时候设置它, 参见 [自定义头部](#pro-table-demo-CustomHeader).
11 changes: 9 additions & 2 deletions packages/pro/table/src/ProTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { computed, defineComponent, provide, ref } from 'vue'

import { isString } from 'lodash-es'

import { type VirtualScrollToOptions } from '@idux/cdk/scroll'
import { IxHeader } from '@idux/components/header'
import { IxSpace } from '@idux/components/space'
import { IxTable, type TableCustomAdditional, type TableCustomTag } from '@idux/components/table'
import { IxTable, type TableCustomAdditional, type TableCustomTag, type TableInstance } from '@idux/components/table'
import { useGlobalConfig } from '@idux/pro/config'

import ProTableLayoutTool from './ProTableLayoutTool'
Expand All @@ -26,7 +27,7 @@ import { proTableProps } from './types'
export default defineComponent({
name: 'IxProTable',
props: proTableProps,
setup(props, { slots }) {
setup(props, { slots, expose }) {
const common = useGlobalConfig('common')
const config = useGlobalConfig('table')
const locale = useGlobalConfig('locale')
Expand All @@ -44,6 +45,11 @@ export default defineComponent({
...columnsContext,
})

const tableRef = ref<TableInstance>()
expose({
scrollTo: (option?: number | VirtualScrollToOptions) => tableRef.value?.scrollTo(option),
})

const headElementRef = ref<HTMLElement>()
const layoutToolStyle = computed(() => {
const headElement = headElementRef.value
Expand Down Expand Up @@ -108,6 +114,7 @@ export default defineComponent({

return (
<IxTable
ref={tableRef}
v-slots={{ ...slots, header: renderHeader, default: renderLayoutTool }}
{...restProps}
class={mergedPrefixCls.value}
Expand Down
9 changes: 8 additions & 1 deletion packages/pro/table/src/ProTableLayoutTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export default defineComponent({

// 只需要判断第一层的即可
const hiddenColumns = computed(() => mergedColumns.value.filter(column => column.visible === false))
const handleCheckAll = (checked: boolean) => loopColumns(mergedColumns.value, column => (column.visible = checked))

const handleCheckAll = (checked: boolean) =>
loopColumns(mergedColumns.value, column => {
// undefined or true
if (column.changeVisible !== false) {
column.visible = checked
}
})

const renderHeader = () => {
const settingLength = mergedColumns.value.length
Expand Down

0 comments on commit cde82e6

Please sign in to comment.