mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 04:37:47 +08:00
915e1ffe26
- Add example for customizing cell - Add example for customize row class
68 lines
1.5 KiB
Vue
68 lines
1.5 KiB
Vue
<template>
|
|
<table-v2 :columns="columns" :data="data" :width="700" :height="400" fixed />
|
|
</template>
|
|
|
|
<script lang="tsx" setup>
|
|
import { ref } from 'vue'
|
|
import dayjs from 'dayjs'
|
|
import { Timer } from '@element-plus/icons-vue'
|
|
import { ElButton, ElIcon, ElTag, ElTooltip } from '@element-plus/components'
|
|
import { FixedDir, TableV2 } from '@element-plus/components/table-v2'
|
|
|
|
import type { Column } from '@element-plus/components/table-v2'
|
|
|
|
let id = 0
|
|
|
|
const dataGenerator = () => ({
|
|
id: `random-id-${++id}`,
|
|
name: 'Tom',
|
|
date: '2020-10-1',
|
|
})
|
|
|
|
const columns: Column<any>[] = [
|
|
{
|
|
key: 'date',
|
|
title: 'Date',
|
|
dataKey: 'date',
|
|
width: 150,
|
|
fixed: FixedDir.LEFT,
|
|
cellRenderer: ({ cellData: date }) => (
|
|
<ElTooltip content={dayjs(date).format('YYYY/MM/DD')}>
|
|
{
|
|
<span class="flex items-center">
|
|
<ElIcon class="mr-3">
|
|
<Timer />
|
|
</ElIcon>
|
|
{dayjs(date).format('YYYY/MM/DD')}
|
|
</span>
|
|
}
|
|
</ElTooltip>
|
|
),
|
|
},
|
|
{
|
|
key: 'name',
|
|
title: 'Name',
|
|
dataKey: 'name',
|
|
width: 150,
|
|
align: 'center',
|
|
cellRenderer: ({ cellData: name }) => <ElTag>{name}</ElTag>,
|
|
},
|
|
{
|
|
key: 'operations',
|
|
title: 'Operations',
|
|
cellRenderer: () => (
|
|
<>
|
|
<ElButton size="small">Edit</ElButton>
|
|
<ElButton size="small" type="danger">
|
|
Delete
|
|
</ElButton>
|
|
</>
|
|
),
|
|
width: 150,
|
|
align: 'center',
|
|
},
|
|
]
|
|
|
|
const data = ref(Array.from({ length: 5000 }).map(dataGenerator))
|
|
</script>
|