mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
feat(components): [table] export columns (#17252)
* feat(components): [el-table] export columns * feat: add test and fix
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -20,7 +20,7 @@ const getAllColumns = <T>(
|
||||
return result
|
||||
}
|
||||
|
||||
const convertToRows = <T>(
|
||||
export const convertToRows = <T>(
|
||||
originColumns: TableColumnCtx<T>[]
|
||||
): TableColumnCtx<T>[] => {
|
||||
let maxLevel = 1
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user