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

89 lines
1.7 KiB
Markdown
Raw Normal View History

# Fixed header and column
A Solution for displaying large amounts of data with long columns.
Note that:
> Specify the width of columns if header and cell do not align properly. If specified width is not working or have gutter between columns, please try to leave one column at least without width to fit fluid layout, or make sure no long word to break table layout.A fixed value which is greater than table width for `scroll-x` is recommended. The sum of unfixed columns should not greater than `scroll-x`.
```html
<n-data-table
ref="table"
:columns="columns"
:data="data"
:pagination="pagination"
max-height="250px"
:scroll-x="1800"
2020-01-10 14:43:10 +08:00
/>
```
```js
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',
render (h, row, index) {
return h('span', ['row ', index])
}
},
{
2020-01-10 14:43:10 +08:00
title: 'Row1',
key: 'row1',
render(h, row, index) {
return h('span', ['row ', index])
}
},
{
2020-01-10 14:43:10 +08:00
title: 'Row2',
key: 'row2',
render(h, row, index) {
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 {
data() {
return {
data,
2020-01-10 14:43:10 +08:00
columns
}
},
computed: {
pagination () {
return { pageSize: 10 }
}
},
methods: {
sendMail(rowData) {
2020-01-10 14:43:10 +08:00
this.$NMessage.info('send mail to ' + rowData.name)
}
}
}
```