naive-ui/demo/documentation/components/data-table/enUS/fixed-header-column.demo.md

89 lines
1.4 KiB
Markdown
Raw Normal View History

# Fixed header and column
A Solution for displaying large amounts of data with long columns.
2020-02-04 22:43:40 +08:00
Note that: If you have set fixed column, you should also set `scroll-x`.
```html
<n-data-table
ref="table"
:columns="columns"
:data="data"
:pagination="pagination"
2020-02-04 22:43:40 +08:00
:max-height="250"
:scroll-x="1800"
2020-01-10 14:43:10 +08:00
/>
```
```js
2020-10-07 03:59:33 +08:00
import { h } from 'vue'
const columns = [
{
2020-01-10 14:43:10 +08:00
title: 'Name',
key: 'name',
width: 200,
2020-01-10 14:43:10 +08:00
fixed: 'left'
},
{
2020-01-10 14:43:10 +08:00
title: 'Age',
key: 'age',
width: 100
},
{
2020-01-10 14:43:10 +08:00
title: 'Row',
key: 'row',
2020-12-12 15:33:41 +08:00
render (row, index) {
2020-01-10 14:43:10 +08:00
return h('span', ['row ', index])
}
},
{
2020-01-10 14:43:10 +08:00
title: 'Row1',
key: 'row1',
2020-12-12 15:33:41 +08:00
render (row, index) {
2020-01-10 14:43:10 +08:00
return h('span', ['row ', index])
}
},
{
2020-01-10 14:43:10 +08:00
title: 'Row2',
key: 'row2',
2020-12-12 15:33:41 +08:00
render (row, index) {
2020-01-10 14:43:10 +08:00
return h('span', ['row ', index])
}
},
{
2020-01-10 14:43:10 +08:00
title: 'Address',
key: 'address',
width: 200,
2020-01-10 14:43:10 +08:00
fixed: 'right'
}
]
2020-01-10 14:43:10 +08:00
const data = Array.apply(null, { length: 46 }).map((_, index) => ({
2020-01-31 17:02:33 +08:00
key: index,
2020-01-10 14:43:10 +08:00
name: `Edward King ${index}`,
age: 32,
address: `London, Park Lane no. ${index}`
}))
export default {
inject: ['message'],
2020-12-12 15:33:41 +08:00
data () {
return {
data,
2020-01-10 14:43:10 +08:00
columns
}
},
computed: {
2020-12-12 15:33:41 +08:00
pagination () {
return { pageSize: 10 }
}
},
methods: {
2020-12-12 15:33:41 +08:00
sendMail (rowData) {
this.message.info('send mail to ' + rowData.name)
}
}
}
```