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