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: 列设置添加冻结列,拖动列 #2031

Open
wants to merge 1 commit into
base: master
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,8 @@
"bugs": {
"url": "https://github.com/x-extends/vxe-table/issues"
},
"homepage": "https://vxetable.cn/"
"homepage": "https://vxetable.cn/",
"dependencies": {
"vuedraggable": "^4.1.0"
}
}
240 changes: 200 additions & 40 deletions packages/toolbar/src/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { formatText } from '../../tools/utils'
import { warnLog, errLog } from '../../tools/log'
import { GlobalEvent } from '../../tools/event'
import { getSlotVNs } from '../../tools/vn'

import draggable from 'vuedraggable'
import { VxeGridConstructor, GridPrivateMethods, ToolbarMethods, VxeToolbarConstructor, VxeToolbarEmits, VxeToolbarPropTypes, VxeTableConstructor, ToolbarPrivateRef, VxeTableMethods, VxeTablePrivateMethods, ToolbarReactData, VxeTableDefines } from '../../../types/all'

export default defineComponent({
Expand Down Expand Up @@ -465,7 +465,7 @@ export default defineComponent({
const renderCustoms = () => {
const { columns } = reactData
const customOpts = computeCustomOpts.value
const colVNs: VNode[] = []
// const colVNs: VNode[] = []
const customBtnOns: {
onClick?: typeof handleClickSettingEvent;
onMouseenter?: typeof handleMouseenterSettingEvent;
Expand Down Expand Up @@ -493,39 +493,92 @@ export default defineComponent({
// 点击触发
customBtnOns.onClick = handleClickSettingEvent
}
XEUtils.eachTree(columns, (column) => {
const colTitle = formatText(column.getTitle(), 1)
const colKey = column.getKey()
const isColGroup = column.children && column.children.length
const isDisabled = checkMethod ? !checkMethod({ column }) : false
if (isColGroup || colKey) {
const isChecked = column.visible
const isIndeterminate = column.halfVisible
colVNs.push(
h('li', {
class: ['vxe-custom--option', `level--${column.level}`, {
'is--group': isColGroup,
'is--checked': isChecked,
'is--indeterminate': isIndeterminate,
'is--disabled': isDisabled
}],
title: colTitle,
onClick: () => {
if (!isDisabled) {
changeCustomOption(column)
}
}
}, [
h('span', {
class: ['vxe-checkbox--icon', isIndeterminate ? GlobalConfig.icon.TABLE_CHECKBOX_INDETERMINATE : (isChecked ? GlobalConfig.icon.TABLE_CHECKBOX_CHECKED : GlobalConfig.icon.TABLE_CHECKBOX_UNCHECKED)]
}),
h('span', {
class: 'vxe-checkbox--label'
}, colTitle)
])
)
}
})
// XEUtils.eachTree(columns, (column) => {
// const colTitle = formatText(column.getTitle(), 1)
// const colKey = column.getKey()
// const isColGroup = column.children && column.children.length
// const isDisabled = checkMethod ? !checkMethod({ column }) : false
// if (isColGroup || colKey) {
// const isChecked = column.visible
// const isIndeterminate = column.halfVisible
// colVNs.push(
// h('li', {
// class: ['vxe-custom--option', `level--${column.level}`, {
// 'is--group': isColGroup,
// 'is--checked': isChecked,
// 'is--indeterminate': isIndeterminate,
// 'is--disabled': isDisabled
// }],
// title: colTitle,
// onClick: () => {
// if (!isDisabled) {
// changeCustomOption(column)
// }
// }
// }, [
// h('div', {
// class: {
// 'vxe-custom--option-left': true,
// 'is--disabled': isDisabled
// }
// }, [
// h('i', {
// class: 'vxe-icon-custom-column',
// async onClick (e: Event) {
// e.stopPropagation()
// }
// })
// ]),
// h('div', {
// class: 'vxe-custom--option-center'
// }, [
// h('span', {
// class: ['vxe-checkbox--icon', isIndeterminate ? GlobalConfig.icon.TABLE_CHECKBOX_INDETERMINATE : (isChecked ? GlobalConfig.icon.TABLE_CHECKBOX_CHECKED : GlobalConfig.icon.TABLE_CHECKBOX_UNCHECKED)]
// }),
// h('span', {
// class: 'vxe-checkbox--label'
// }, colTitle)
// ]),
// h('div', {
// class: 'vxe-custom--option-right'
// }, [
// h('span', {
// class: {
// 'vxe-icon-arrow-left': true,
// 'is--active': column.fixed === 'left',
// 'is--disabled': isDisabled
// },
// async onClick (e: Event) {
// e.stopPropagation()
// if (isDisabled) {
// return
// }
// column.fixed = 'left'
// await nextTick()
// $xegrid?.refreshColumn()
// }
// }),
// h('span', {
// class: {
// 'vxe-icon-arrow-right': true,
// 'is--active': column.fixed === 'right',
// 'is--disabled': isDisabled
// },
// async onClick (e: Event) {
// e.stopPropagation()
// if (isDisabled) {
// return
// }
// column.fixed = 'right'
// await nextTick()
// $xegrid?.refreshColumn()
// }
// })
// ])
// ])
// )
// }
// })
const isAllChecked = customStore.isAll
const isAllIndeterminate = customStore.isIndeterminate
return h('div', {
Expand Down Expand Up @@ -562,10 +615,33 @@ export default defineComponent({
}, GlobalConfig.i18n('vxe.toolbar.customAll'))
])
]),
h('ul', {
class: 'vxe-custom--body',
...customWrapperOns
}, colVNs),
// h('ul', {
// class: 'vxe-custom--body',
// ...customWrapperOns
// }, colVNs),
h(
draggable,
{
tag: 'ul',
itemKey: 'title',
handle: '.vxe-custom--option-left',
group: 'level--top',
modelValue: columns,
'onUpdate:modelValue': async (value: any) => {
reactData.columns = value
await nextTick()
// 刷新列
$xegrid?.loadColumn(reactData.columns)
},
class: 'vxe-custom--body',
...customWrapperOns
},
{
item: (items: any) => [
h('li', draggableRender(items.element, checkMethod))
]
}
),
customOpts.isFooter === false ? null : h('div', {
class: 'vxe-custom--footer'
}, [
Expand All @@ -582,6 +658,91 @@ export default defineComponent({
])
}

const draggableRender = (column: any, checkMethod: any) => {
const colTitle = formatText(column.getTitle(), 1)
const colKey = column.getKey()
const isColGroup = column.children && column.children.length
const isDisabled = checkMethod ? !checkMethod({ column }) : false
if (isColGroup || colKey) {
const isChecked = column.visible
const isIndeterminate = column.halfVisible
return h('li', {
class: ['vxe-custom--option', `level--${column.level}`, {
'is--group': isColGroup,
'is--checked': isChecked,
'is--indeterminate': isIndeterminate,
'is--disabled': isDisabled
}],
title: colTitle,
onClick: () => {
if (!isDisabled) {
changeCustomOption(column)
}
}
}, [
h('div', {
class: {
'vxe-custom--option-left': true,
'is--disabled': isDisabled
}
}, [
h('i', {
class: 'vxe-icon-custom-column',
async onClick (e: Event) {
e.stopPropagation()
}
})
]),
h('div', {
class: 'vxe-custom--option-center'
}, [
h('span', {
class: ['vxe-checkbox--icon', isIndeterminate ? GlobalConfig.icon.TABLE_CHECKBOX_INDETERMINATE : (isChecked ? GlobalConfig.icon.TABLE_CHECKBOX_CHECKED : GlobalConfig.icon.TABLE_CHECKBOX_UNCHECKED)]
}),
h('span', {
class: 'vxe-checkbox--label'
}, colTitle)
]),
h('div', {
class: 'vxe-custom--option-right'
}, [
h('span', {
class: {
'vxe-icon-arrow-left': true,
'is--active': column.fixed === 'left',
'is--disabled': isDisabled
},
async onClick (e: Event) {
e.stopPropagation()
if (isDisabled) {
return
}
column.fixed = column.fixed === 'left' ? undefined : 'left'
await nextTick()
$xegrid?.refreshColumn()
}
}),
h('span', {
class: {
'vxe-icon-arrow-right': true,
'is--active': column.fixed === 'right',
'is--disabled': isDisabled
},
async onClick (e: Event) {
e.stopPropagation()
if (isDisabled) {
return
}
column.fixed = column.fixed === 'right' ? undefined : 'right'
await nextTick()
$xegrid?.refreshColumn()
}
})
])
])
}
}

toolbarMethods = {
dispatchEvent (type, params, evnt) {
emit(type, Object.assign({ $toolbar: $xetoolbar, $event: evnt }, params))
Expand Down Expand Up @@ -675,7 +836,6 @@ export default defineComponent({
}

$xetoolbar.renderVN = renderVN

return $xetoolbar
},
render () {
Expand Down
23 changes: 23 additions & 0 deletions styles/toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@
&:hover {
background-color: $vxe-table-row-hover-background-color;
}
display: flex;
align-items: center;
justify-content: space-between;
[class^="vxe-custom--option-left"] {
margin-right: 11px;
color: $vxe-font-color;

}
[class^="vxe-custom--option-right"] {
margin-left: 11px;
color: $vxe-font-color;
.vxe-icon-arrow-left, .vxe-icon-arrow-right{
&.is--active {
color: $vxe-primary-color;
}
&.is--disabled {
color: $vxe-disabled-color;
}
}
}
[class^="vxe-custom--option-center"] {
flex: 1;
}
}
}
.vxe-custom--header,
Expand Down