Customize k-picker columns and headers using slots
You can customize the rendering of specific columns and headers in k-picker by using slots. To enable custom rendering for a column, add custom and header properties to the column definition in tableColumn.
- Use
#header-{headerName}to customize the column header. - Use
#{columnProp}to customize the cell content (provides{ row }in the slot scope). - Use
#right-headerto add custom content to the right side of the picker header.
<template>
<k-picker
:table-column="tableColumn"
:table-data="tableData"
v-model="multipleSelection"
>
<!-- Custom Header for 'address' column -->
<template #header-address>
<el-tag>自定义表头</el-tag>
</template>
<!-- Custom Cell for 'address' column -->
<template #address="{ row }">
{{ `custom: ${row.address}` }}
</template>
<!-- Custom Right Header content -->
<template #right-header>
<el-tag>自定义右侧表头</el-tag>
</template>
<template #footer>
<k-button type="primary" @click="clickHandle">确认</k-button>
</template>
</k-picker>
</template>
<script setup>
const tableColumn = [
{ label: '日期', prop: 'date' },
{ label: '姓名', prop: 'name' },
{
label: '地址',
prop: 'address',
custom: 'address', // Matches the slot name #address
header: 'header-address', // Matches the slot name #header-address
},
];
// ... tableData and multipleSelection definitions
</script>