feat(components): [table] export columns (#17252)

* feat(components): [el-table] export columns

* feat: add test and fix
This commit is contained in:
sea
2024-06-19 21:12:09 +08:00
committed by GitHub
parent ff936c76b5
commit 32ed206b1f
4 changed files with 33 additions and 1 deletions

View File

@@ -332,6 +332,8 @@ table/table-layout
| scrollTo | scrolls to a particular set of coordinates | ^[Function]`(options: number \| ScrollToOptions, yCoord?: number) => void` |
| setScrollTop | set vertical scroll position | ^[Function]`(top?: number) => void` |
| setScrollLeft | set horizontal scroll position | ^[Function]`(left?: number) => void` |
| columns ^(2.7.6) | Get table columns context. | ^[array]`TableColumnCtx<T>[]` |
## Table-column API

View File

@@ -1019,6 +1019,30 @@ describe('Table.vue', () => {
wrapper.unmount()
})
it('get table columns', async () => {
const wrapper = mount({
components: {
ElTable,
ElTableColumn,
},
template: `
<div>
<el-table ref="table" :data="testData" highlight-current-row>
<el-table-column prop="name" sortable />
<el-table-column prop="release" sortable />
</el-table>
</div>
`,
data() {
return { testData: getTestData() }
},
})
const vm = wrapper.vm
await doubleWait()
expect(vm.$refs.table.columns.length).toBe(2)
wrapper.unmount()
})
})
it('hover', async () => {

View File

@@ -20,7 +20,7 @@ const getAllColumns = <T>(
return result
}
const convertToRows = <T>(
export const convertToRows = <T>(
originColumns: TableColumnCtx<T>[]
): TableColumnCtx<T>[] => {
let maxLevel = 1

View File

@@ -177,6 +177,7 @@ import TableHeader from './table-header'
import TableBody from './table-body'
import TableFooter from './table-footer'
import useUtils from './table/utils-helper'
import { convertToRows } from './table-header/utils-helper'
import useStyle from './table/style-helper'
import useKeyRender from './table/key-render-helper'
import defaultProps from './table/defaults'
@@ -294,12 +295,17 @@ export default defineComponent({
return props.emptyText || t('el.table.emptyText')
})
const columns = computed(() => {
return convertToRows(store.states.originColumns.value)[0]
})
useKeyRender(table)
return {
ns,
layout,
store,
columns,
handleHeaderFooterMousewheel,
handleMouseLeave,
tableId,