element-plus/docs/examples/table-v2/auto-resizer.vue
JeremyWuuuuu 090706250b
feat(components): [auto-resizer] new component (#7541)
* feat(components): [auto-resizer] new component

- Add new component AutoResizer for skip passing width/height.
- Update documentation for AutoResizer.
- Update FAQs for TableV2.
- Update interfaces for TableV2.

* Fix linter error

* Fix linter issue
2022-05-07 09:47:32 +08:00

48 lines
1.1 KiB
Vue

<template>
<div style="height: 400px">
<el-auto-resizer>
<template #default="{ height, width }">
<el-table-v2
:columns="columns"
:data="data"
:width="width"
:height="height"
fixed
/>
</template>
</el-auto-resizer>
</div>
</template>
<script lang="ts" setup>
const generateColumns = (length = 10, prefix = 'column-', props?: any) =>
Array.from({ length }).map((_, columnIndex) => ({
...props,
key: `${prefix}${columnIndex}`,
dataKey: `${prefix}${columnIndex}`,
title: `Column ${columnIndex}`,
width: 150,
}))
const generateData = (
columns: ReturnType<typeof generateColumns>,
length = 200,
prefix = 'row-'
) =>
Array.from({ length }).map((_, rowIndex) => {
return columns.reduce(
(rowData, column, columnIndex) => {
rowData[column.dataKey] = `Row ${rowIndex} - Col ${columnIndex}`
return rowData
},
{
id: `${prefix}${rowIndex}`,
parentId: null,
}
)
})
const columns = generateColumns(10)
const data = generateData(columns, 200)
</script>