naive-ui/demo/documentation/components/dataTable/enUS/renderHeader.md

102 lines
1.6 KiB
Markdown
Raw Normal View History

2020-01-10 14:43:10 +08:00
# Custom Render Column Header
```html
<n-data-table
2020-01-10 14:43:10 +08:00
ref='table'
:columns='columns'
:data='data'
:pagination='pagination'
/>
```
```js
const renderTooltip = (h, activator, content) => {
const scopedSlots = {
2020-01-10 14:43:10 +08:00
activator: () => activator,
default: () => content
}
2020-01-10 14:43:10 +08:00
return h('n-tooltip', {
props: {
arrow: true
},
scopedSlots
})
}
const createColumns = instance => {
return [
{
2020-01-10 14:43:10 +08:00
key: 'name',
title (h, column) {
return renderTooltip(
h,
2020-01-10 14:43:10 +08:00
h('n-gradient-text', {
props: {
size: 24,
type: 'danger'
}
}, 'Name'),
'Tooltip Content'
)
}
},
{
2020-01-10 14:43:10 +08:00
key: 'age',
title (h, column) {
return h('n-gradient-text', {
props: {
size: '20',
type: 'info'
}
}, 'Age')
}
},
{
2020-01-10 14:43:10 +08:00
key: 'address',
title (h, column) {
return h(
'n-gradient-text', {
props: {
size: '16',
type: 'warning'
}
}, 'Address')
}
}
]
}
const data = [
{
2020-01-31 17:02:33 +08:00
key: 0,
2020-01-10 14:43:10 +08:00
name: 'John Brown',
age: 32,
2020-01-10 14:43:10 +08:00
address: 'New York No. 1 Lake Park'
},
{
2020-01-31 17:02:33 +08:00
key: 1,
2020-01-10 14:43:10 +08:00
name: 'Jim Green',
age: 42,
2020-01-10 14:43:10 +08:00
address: 'London No. 1 Lake Park'
},
{
2020-01-31 17:02:33 +08:00
key: 2,
2020-01-10 14:43:10 +08:00
name: 'Joe Black',
age: 32,
2020-01-10 14:43:10 +08:00
address: 'Sidney No. 1 Lake Park'
}
]
2020-01-10 14:43:10 +08:00
export default {
2020-01-10 14:43:10 +08:00
data () {
return {
data: data,
2020-01-10 14:43:10 +08:00
columns: createColumns(this),
pagination: {
pageSize: 10
}
}
}
}
```