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: 增加floating-ui用于浮动面板展示,FilterConfig增加isFloating属性是否浮动 #2240

Open
wants to merge 3 commits 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
3 changes: 3 additions & 0 deletions examples/views/table/renderer/Filter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<vxe-table
border
height="400"
:filter-config="{
isFloating: true,
}"
:data="tableData">
<vxe-column type="seq" width="60"></vxe-column>
<vxe-column field="name" title="文本筛选" :filters="nameOptions" :filter-render="{name: 'FilterInput'}"></vxe-column>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"style": "lib/style.css",
"typings": "types/index.d.ts",
"dependencies": {
"@floating-ui/vue": "^1.0.2",
"dom-zindex": "^1.0.1",
"xe-utils": "^3.5.14"
},
Expand Down
30 changes: 27 additions & 3 deletions packages/table/src/table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, getCurrentInstance, h, createCommentVNode, ComponentPublicInstance, resolveComponent, ComponentOptions, reactive, ref, Ref, provide, inject, nextTick, onActivated, onDeactivated, onBeforeUnmount, onUnmounted, watch, computed, ComputedRef, onMounted } from 'vue'
import { defineComponent, getCurrentInstance, h, createCommentVNode, ComponentPublicInstance, resolveComponent, ComponentOptions, reactive, ref, Ref, provide, inject, nextTick, onActivated, onDeactivated, onBeforeUnmount, onUnmounted, watch, computed, ComputedRef, onMounted, Teleport } from 'vue'
import XEUtils from 'xe-utils'
import { browse, isPx, isScale, hasClass, addClass, removeClass, getEventTargetNode, getPaddingTopBottomSize, setScrollTop, setScrollLeft, isNodeElement } from '../../tools/dom'
import { getLastZIndex, nextZIndex, hasChildrenList, getFuncText, isEnableConf, formatText, eqEmptyValue } from '../../tools/utils'
Expand All @@ -17,6 +17,7 @@ import tableEmits from './emits'
import VxeLoading from '../../loading/index'
import { getRowUniqueId, clearTableAllStatus, getRowkey, getRowid, rowToVisible, colToVisible, getCellValue, setCellValue, handleFieldOrColumn, toTreePathSeq, restoreScrollLocation, restoreScrollListener, XEBodyScrollElement, getRootColumn } from './util'
import { getSlotVNs } from '../../tools/vn'
import { useFloating, autoUpdate, offset, flip } from '@floating-ui/vue'

import { VxeGridConstructor, VxeGridPrivateMethods, VxeTableConstructor, TableReactData, TableInternalData, VxeTablePropTypes, VxeToolbarConstructor, VxeTooltipInstance, TablePrivateMethods, VxeTablePrivateRef, VxeTablePrivateComputed, VxeTablePrivateMethods, VxeTableMethods, TableMethods, VxeMenuPanelInstance, VxeTableDefines, VxeTableProps, VxeColumnPropTypes, VxeTableDataRow } from '../../../types/all'

Expand Down Expand Up @@ -339,6 +340,17 @@ export default defineComponent({
const $xegrid = inject<(VxeGridConstructor & VxeGridPrivateMethods) | null>('$xegrid', null)
let $xetoolbar: VxeToolbarConstructor

const reference = ref<HTMLDivElement|null>(null)

const { floatingStyles } = useFloating(reference, refTableFilter, {
// 浮动元素跟随目标元素
whileElementsMounted (...args) {
const cleanup = autoUpdate(...args, { animationFrame: true })
return cleanup
},
middleware: [offset(10), flip()]
})

const computeValidOpts = computed(() => {
return Object.assign({}, GlobalConfig.table.validConfig, props.validConfig) as VxeTablePropTypes.ValidOpts
})
Expand Down Expand Up @@ -1379,7 +1391,10 @@ export default defineComponent({
if (sortMultiple && chronological && orderColumns.length > 1) {
orderColumns = XEUtils.orderBy(orderColumns, 'sortTime')
}

// 处理是否有筛选列
if (tableFullColumn.findIndex(item => item.filters) > -1 && filterOpts.isFloating) {
reactData.initStore.filter = true
}
// 处理筛选
// 支持单列、多列、组合筛选
if (!allRemoteFilter && filterColumns.length) {
Expand Down Expand Up @@ -4470,6 +4485,8 @@ export default defineComponent({
if (tableFilter) {
if (getEventTargetNode(evnt, el, 'vxe-cell--filter').flag) {
// 如果点击了筛选按钮
// 获取到元素位置
reference.value = getEventTargetNode(evnt, el, 'vxe-cell--filter').targetElem
} else if (getEventTargetNode(evnt, tableFilter.$el as HTMLDivElement).flag) {
// 如果点击筛选容器
} else {
Expand Down Expand Up @@ -6617,6 +6634,7 @@ export default defineComponent({
const mouseOpts = computeMouseOpts.value
const validTipOpts = computeValidTipOpts.value
const loadingOpts = computeLoadingOpts.value
const filterOpts = computeFilterOpts.value
const isMenu = computeIsMenu.value
return h('div', {
ref: refElem,
Expand Down Expand Up @@ -6740,7 +6758,13 @@ export default defineComponent({
/**
* 筛选
*/
initStore.filter ? h(resolveComponent('vxe-table-filter') as ComponentOptions, {
initStore.filter ? filterOpts.isFloating ? h(Teleport, {
to: 'body'
}, [h(resolveComponent('vxe-table-filter'), {
ref: refTableFilter,
filterStore,
style: floatingStyles.value
})]) : h(resolveComponent('vxe-table-filter') as ComponentOptions, {
ref: refTableFilter,
filterStore
}) : createCommentVNode(),
Expand Down
1 change: 1 addition & 0 deletions types/table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,7 @@ export namespace VxeTablePropTypes {
showIcon?: boolean
iconNone?: string
iconMatch?: string
isFloating?: boolean
}
export interface FilterOpts<D = VxeTableDataRow> extends FilterConfig<D> { }

Expand Down