Skip to content

Commit

Permalink
releases 4.7.89
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Oct 16, 2024
1 parent b669c0e commit 154de68
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 57 deletions.
128 changes: 76 additions & 52 deletions examples/views/table/TableTest8.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
<template>
<div>
<vxe-button @click="scrollCol">滚动列</vxe-button>
<vxe-table
border
ref="tableRef"
height="400"
:data="tableData">
<vxe-column type="seq" width="70"></vxe-column>
<vxe-column field="name" title="Name" width="180"></vxe-column>
<vxe-column field="role" title="Role" width="300"></vxe-column>
<vxe-column field="age" title="Age" width="200"></vxe-column>
<vxe-column field="sex" title="Sex" width="200"></vxe-column>
<vxe-column field="num" title="Num" width="260"></vxe-column>
<vxe-column field="num11" title="Num11" width="200"></vxe-column>
<vxe-column field="num22" title="Num22" width="250"></vxe-column>
<vxe-column field="num33" title="Num33" width="100"></vxe-column>
<vxe-column field="num44" title="Num44" width="180"></vxe-column>
<vxe-column field="num55" title="Num55" width="260"></vxe-column>
<vxe-column field="num66" title="Num66" width="360"></vxe-column>
<vxe-column field="date3" title="Date" width="140"></vxe-column>
<vxe-column field="num77" title="Num77" width="260"></vxe-column>
<vxe-column field="num88" title="Num88" width="260"></vxe-column>
<vxe-column field="address" title="Address" width="200" show-overflow></vxe-column>
</vxe-table>
<vxe-button @click="scrollToCol('attr1')">定位 Attr1 列</vxe-button>
<vxe-button @click="scrollToCol('attr4')">定位 Attr4 列</vxe-button>
<vxe-button @click="scrollToCol('attr8')">定位 Attr8 列</vxe-button>
<vxe-button @click="scrollToRow(gridOptions.data[3])">定位第4行</vxe-button>
<vxe-button @click="scrollToRow(gridOptions.data[9])">定位第10行</vxe-button>
<vxe-button @click="scrollToRow(gridOptions.data[15])">定位第16行</vxe-button>
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import type { VxeTableInstance } from '../../../types'
import { ref, reactive } from 'vue'
import { VxeGridInstance, VxeGridProps } from '../../../types'
interface RowVO {
id: number
Expand All @@ -37,37 +21,77 @@ interface RowVO {
sex: string
age: number
address: string
attr1: string
attr2: string
attr3: string
attr4: string
attr5: string
attr6: string
attr7: string
attr8: string
attr9: string
attr10: string
}
const tableRef = ref<VxeTableInstance>()
const gridRef = ref<VxeGridInstance<RowVO>>()
const tableData = ref<RowVO[]>([
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 23, address: 'test abc' },
{ id: 10005, name: 'Test5', role: 'Develop', sex: 'Women', age: 30, address: 'Shanghai' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: 'Women', age: 21, address: 'test abc' },
{ id: 10007, name: 'Test7', role: 'Test', sex: 'Man', age: 29, address: 'test abc' },
{ id: 10008, name: 'Test8', role: 'Develop', sex: 'Man', age: 35, address: 'test abc' },
{ id: 10009, name: 'Test9', role: 'Test', sex: 'Man', age: 26, address: 'test abc' },
{ id: 10010, name: 'Test10', role: 'Develop', sex: 'Man', age: 38, address: 'test abc' },
{ id: 10011, name: 'Test11', role: 'Test', sex: 'Women', age: 29, address: 'test abc' },
{ id: 10012, name: 'Test12', role: 'Develop', sex: 'Man', age: 27, address: 'test abc' },
{ id: 10013, name: 'Test13', role: 'Test', sex: 'Women', age: 24, address: 'test abc' },
{ id: 10014, name: 'Test14', role: 'Develop', sex: 'Man', age: 34, address: 'test abc' },
{ id: 10015, name: 'Test15', role: 'Test', sex: 'Man', age: 21, address: 'test abc' },
{ id: 10016, name: 'Test16', role: 'Develop', sex: 'Women', age: 20, address: 'test abc' },
{ id: 10017, name: 'Test17', role: 'Test', sex: 'Man', age: 31, address: 'test abc' },
{ id: 10018, name: 'Test18', role: 'Develop', sex: 'Women', age: 32, address: 'test abc' },
{ id: 10019, name: 'Test19', role: 'Test', sex: 'Man', age: 37, address: 'test abc' },
{ id: 10020, name: 'Test20', role: 'Develop', sex: 'Man', age: 41, address: 'test abc' }
])
const gridOptions = reactive<VxeGridProps<RowVO> & { data: RowVO[] }>({
border: true,
showOverflow: true,
height: 400,
columns: [
{ type: 'seq', width: 70, fixed: 'left' },
{ field: 'name', title: 'Name', fixed: 'left', width: 200 },
{ field: 'role', title: 'Role', width: 300 },
{ field: 'attr1', title: 'Attr1', width: 400 },
{ field: 'attr2', title: 'Attr2', width: 300 },
{ field: 'attr3', title: 'Attr3', width: 700 },
{ field: 'attr4', title: 'Attr4', width: 600 },
{ field: 'attr5', title: 'Attr5', width: 500 },
{ field: 'attr6', title: 'Attr6', width: 400 },
{ field: 'attr7', title: 'Attr7', width: 200 },
{ field: 'attr8', title: 'Attr8', width: 500 },
{ field: 'attr9', title: 'Attr9', width: 600 },
{ field: 'attr10', title: 'Attr10', width: 500 },
{ field: 'age', title: 'Age', width: 200 },
{ field: 'sex', title: 'Sex', fixed: 'right', width: 100 },
{ field: 'address', title: 'Address', fixed: 'right', width: 140 }
],
data: [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 23, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10005, name: 'Test5', role: 'Develop', sex: 'Women', age: 30, address: 'Shanghai', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: 'Women', age: 21, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10007, name: 'Test7', role: 'Test', sex: 'Man', age: 29, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10008, name: 'Test8', role: 'Develop', sex: 'Man', age: 35, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10009, name: 'Test9', role: 'Test', sex: 'Man', age: 26, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10010, name: 'Test10', role: 'Develop', sex: 'Man', age: 38, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10011, name: 'Test11', role: 'Test', sex: 'Women', age: 29, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10012, name: 'Test12', role: 'Develop', sex: 'Man', age: 27, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10013, name: 'Test13', role: 'Test', sex: 'Women', age: 24, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10014, name: 'Test14', role: 'Develop', sex: 'Man', age: 34, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10015, name: 'Test15', role: 'Test', sex: 'Man', age: 21, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10016, name: 'Test16', role: 'Develop', sex: 'Women', age: 20, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10017, name: 'Test17', role: 'Test', sex: 'Man', age: 31, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10018, name: 'Test18', role: 'Develop', sex: 'Women', age: 32, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10019, name: 'Test19', role: 'Test', sex: 'Man', age: 37, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
{ id: 10020, name: 'Test20', role: 'Develop', sex: 'Man', age: 41, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' }
]
})
const scrollCol = () => {
const $table = tableRef.value
if ($table) {
$table.scrollToColumn('num33')
const scrollToCol = (field: string) => {
const $grid = gridRef.value
if ($grid) {
$grid.scrollToColumn(field)
}
}
const scrollToRow = (row: RowVO) => {
const $grid = gridRef.value
if ($grid) {
$grid.scrollToRow(row)
}
}
</script>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table",
"version": "4.7.88",
"version": "4.7.89",
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、列拖拽,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand Down
9 changes: 5 additions & 4 deletions packages/table/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,18 @@ export function colToVisible ($xeTable: VxeTableConstructor & VxeTablePrivateMet
if (tdElem) {
const tdOffsetParent = tdElem.offsetParent as HTMLElement
const tdOffsetLeft = tdElem.offsetLeft + (tdOffsetParent ? tdOffsetParent.offsetLeft : 0)
const tdWidth = tdElem.clientWidth
const cellWidth = tdElem.clientWidth
// 检测是否在可视区中
if (tdOffsetLeft < (bodySrcollLeft + offsetFixedLeft)) {
return $xeTable.scrollTo(tdOffsetLeft - offsetFixedLeft - 1)
} else if ((tdOffsetLeft + tdWidth) >= (bodyWidth + bodySrcollLeft - offsetFixedRight)) {
return $xeTable.scrollTo(tdOffsetLeft - offsetFixedLeft - offsetFixedRight + 1)
} else if ((tdOffsetLeft + cellWidth - bodySrcollLeft) > (bodyWidth - offsetFixedRight)) {
return $xeTable.scrollTo((tdOffsetLeft + cellWidth) - (bodyWidth - offsetFixedRight - 1))
}
} else {
// 检测是否在虚拟渲染可视区中
if (scrollXLoad) {
let scrollLeft = 0
const cellWidth = column.renderWidth
for (let index = 0; index < visibleColumn.length; index++) {
const currCol = visibleColumn[index]
if (currCol === column || currCol.id === column.id) {
Expand All @@ -454,7 +455,7 @@ export function colToVisible ($xeTable: VxeTableConstructor & VxeTablePrivateMet
if (scrollLeft < bodySrcollLeft) {
return $xeTable.scrollTo(scrollLeft - offsetFixedLeft - 1)
}
return $xeTable.scrollTo(scrollLeft - offsetFixedLeft - offsetFixedRight + 1)
return $xeTable.scrollTo((scrollLeft + cellWidth) - (bodyWidth - offsetFixedRight - 1))
}
}
}
Expand Down

0 comments on commit 154de68

Please sign in to comment.