2020-01-07 17:32:10 +08:00
|
|
|
# Controlled Pagination
|
2020-12-12 14:44:44 +08:00
|
|
|
|
2020-01-07 17:32:10 +08:00
|
|
|
```html
|
|
|
|
<n-data-table
|
|
|
|
ref="table"
|
|
|
|
:columns="columns"
|
|
|
|
:data="data"
|
|
|
|
:pagination="pagination"
|
|
|
|
/>
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
key: 'name'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
key: 'age'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Address',
|
|
|
|
key: 'address'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2020-04-23 18:36:54 +08:00
|
|
|
const data = Array.apply(null, { length: 46 }).map((_, index) => ({
|
|
|
|
key: index,
|
|
|
|
name: `Edward King ${index}`,
|
|
|
|
age: 32,
|
|
|
|
address: `London, Park Lane no. ${index}`
|
|
|
|
}))
|
|
|
|
|
2020-01-07 17:32:10 +08:00
|
|
|
export default {
|
2020-12-12 15:33:41 +08:00
|
|
|
data () {
|
2020-01-07 17:32:10 +08:00
|
|
|
return {
|
|
|
|
data,
|
|
|
|
columns,
|
|
|
|
pagination: {
|
|
|
|
page: 2,
|
2020-04-23 18:36:54 +08:00
|
|
|
pageSize: 5,
|
|
|
|
showSizePicker: true,
|
|
|
|
pageSizes: [3, 5, 7],
|
2020-12-12 14:44:44 +08:00
|
|
|
onChange: (page) => {
|
2020-01-07 17:32:10 +08:00
|
|
|
this.pagination.page = page
|
2020-04-23 18:36:54 +08:00
|
|
|
},
|
2020-12-12 14:44:44 +08:00
|
|
|
onPageSizeChange: (pageSize) => {
|
2020-04-23 18:36:54 +08:00
|
|
|
this.pagination.pageSize = pageSize
|
2020-01-07 17:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-30 16:10:20 +08:00
|
|
|
}
|
2020-12-12 14:44:44 +08:00
|
|
|
```
|