2019-12-12 14:27:31 +08:00
|
|
|
# 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`.
|
2019-12-12 14:27:31 +08:00
|
|
|
|
|
|
|
```html
|
2019-12-31 21:01:24 +08:00
|
|
|
<n-data-table
|
2019-12-12 14:27:31 +08:00
|
|
|
ref="table"
|
|
|
|
:columns="columns"
|
|
|
|
:data="data"
|
|
|
|
:pagination="pagination"
|
2020-02-04 22:43:40 +08:00
|
|
|
:max-height="250"
|
2020-01-08 01:36:12 +08:00
|
|
|
:scroll-x="1800"
|
2020-01-10 14:43:10 +08:00
|
|
|
/>
|
2019-12-12 14:27:31 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
2020-01-05 22:46:13 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
2020-01-10 14:43:10 +08:00
|
|
|
title: 'Name',
|
|
|
|
key: 'name',
|
2020-01-05 22:46:13 +08:00
|
|
|
width: 200,
|
2020-01-10 14:43:10 +08:00
|
|
|
fixed: 'left'
|
2020-01-05 22:46:13 +08:00
|
|
|
},
|
|
|
|
{
|
2020-01-10 14:43:10 +08:00
|
|
|
title: 'Age',
|
|
|
|
key: 'age',
|
2020-01-05 22:46:13 +08:00
|
|
|
width: 100
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 14:43:10 +08:00
|
|
|
title: 'Row',
|
|
|
|
key: 'row',
|
|
|
|
render (h, row, index) {
|
|
|
|
return h('span', ['row ', index])
|
2020-01-05 22:46:13 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 14:43:10 +08:00
|
|
|
title: 'Row1',
|
|
|
|
key: 'row1',
|
|
|
|
render(h, row, index) {
|
|
|
|
return h('span', ['row ', index])
|
2020-01-05 22:46:13 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 14:43:10 +08:00
|
|
|
title: 'Row2',
|
|
|
|
key: 'row2',
|
|
|
|
render(h, row, index) {
|
|
|
|
return h('span', ['row ', index])
|
2019-12-12 14:27:31 +08:00
|
|
|
}
|
2020-01-05 22:46:13 +08:00
|
|
|
},
|
|
|
|
{
|
2020-01-10 14:43:10 +08:00
|
|
|
title: 'Address',
|
|
|
|
key: 'address',
|
2020-01-05 22:46:13 +08:00
|
|
|
width: 200,
|
2020-01-10 14:43:10 +08:00
|
|
|
fixed: 'right'
|
2020-01-05 22:46:13 +08:00
|
|
|
}
|
|
|
|
]
|
2019-12-12 14:27:31 +08:00
|
|
|
|
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}`
|
|
|
|
}))
|
|
|
|
|
2020-01-05 22:46:13 +08:00
|
|
|
|
2019-12-12 14:27:31 +08:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-01-05 22:46:13 +08:00
|
|
|
data,
|
2020-01-10 14:43:10 +08:00
|
|
|
columns
|
2020-01-05 22:46:13 +08:00
|
|
|
}
|
2019-12-12 14:27:31 +08:00
|
|
|
},
|
|
|
|
computed: {
|
2020-01-05 22:46:13 +08:00
|
|
|
pagination () {
|
2020-01-06 17:31:52 +08:00
|
|
|
return { pageSize: 10 }
|
2019-12-12 14:27:31 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
sendMail(rowData) {
|
2020-01-10 14:43:10 +08:00
|
|
|
this.$NMessage.info('send mail to ' + rowData.name)
|
2019-12-12 14:27:31 +08:00
|
|
|
}
|
|
|
|
}
|
2020-01-05 22:46:13 +08:00
|
|
|
}
|
2019-12-12 14:27:31 +08:00
|
|
|
```
|